开发者

JavaScript jQuery Animate

Hi i have done a code that i need to toggle. How can i do it with this code?

    var divh = document.getElementById('first').offsetHeight;

document.getElementById("first").style.heig开发者_Python百科ht = "100px";

$("div:first").click(function(){
  $("#first").stop().animate({
    height: divh 
  }, 1000 );
});


If I correctly understand, you want to toggle height of the div from it's current state to 100px and backward. So why don't you want to use .toggle() method instead? Like this:

//keep default height
var divh = $('#first').outerHeight();

//toggle functions
$('div:first').toggle(
  function () {
     $('#first').stop().animate({
        height: divh +'px'
     }, 1000);
  },
  function () {
    $('#first').stop().animate({
      height: '100px'
    }, 1000);
  }
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜