开发者

JavaScript jQuery Animate

开发者 https://www.devze.com 2023-02-11 02:55 出处:网络
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;

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

精彩评论

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