jQuery之.stop()方法的理解

//jQuery基础教程 第四版 p227
$(document).ready(function() { $('div.member').on('mouseenter mouseleave', function(event) { var size = event.type == 'mouseenter' ? 85 : 75; var padding = event.type == 'mouseenter' ? 0 : 5; $(this).find('img').stop().animate({ width: size, height: size, paddingTop: padding, paddingLeft: padding }); }); });

一直不太明白stop方法的工作原理。以前的错误理解是在动画之前执行stop方法,那动画不就被停止了,可测试的时候,动画依然执行,一直很困惑。

后来查看jQurey API发现是Stop the currently-running animation on the matched elements

我的理解是mouseenter时,当前还没有动画,就无所谓停止动画了(不执行stop方法),就执行后面的animate({.....})了。而当这个动画还没执行完成时,就立即mouseleave,此时就执行stop,立即停止当前未完成的动画。然后执行新动画

posted @ 2015-04-06 10:49  丁丁0313  阅读(335)  评论(0编辑  收藏  举报