jQuery: div pops back to full size after animation

点点圈 提交于 2019-12-06 11:58:19

Looks like if I grab the width of the 'outer' div, and the outerWidth of the 'inner' div, then subtract the 'outer' div's width from the 'inner' div's outerWidth, and animate the 'outer' width to the result simultaneously while animating the 'inner' to 0, it works.

Any opinions on whether this should be a bug fix request for jquery or webkit or both.

$('.outer').click(function() { 
    var innerWidth = $('.inner').outerWidth();
    var outerWidth = $('.outer').width();
    var theWidth = outerWidth - innerWidth;
    $('.inner').animate({width: 0, paddingLeft: 0, paddingRight: 0}, 'slow' );
    $('.outer').animate({width: theWidth}, 'slow');
});

Have you tried setting the outerbox width to 0 after the animation is complete?

$('.inner').animate({width: 0, paddingLeft: 0, paddingRight: 0}, 'slow', function() {
  $('.outer').css("width", 0);
});

For me in Firefox 3.0.10 using jQuery 1.3.2 in Ubuntu 9.04 this works perfectly. May be it's some kind of interaction with other html elements in your page?

In my tests, this works fine in IE, FF and Opera, but produces the bug you mention in Chrome and Safari.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!