<button id="clear">clearqueue</button>
<span id="1" style="background-color:yellow; width:100px">I am script 1</span><br />
<span id="2" style="background-color:pink; width:100px">I am script 2</span>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$( 'span#1' ).animate({'width': '300px'},1000)
.queue(function(){$( 'span#2' ).animate({'width': '300px'},1000);
});
</script>
<script type="text/javascript">
$('#clear').click(function(){$('span#1').clearqueue();});
</script>
我试图在点击按钮后停止动画,但它不起作用。希望得到另一双眼睛的帮助。
答案 0 :(得分:0)
clearQueue()是在camelCase中尝试写的,
$('#clear').click(function(){$('span#1').clearQueue()});
clearQueue()不会停止当前正在运行的动画,因为你需要stop()而不是clearQueue()它可以工作,
$('#clear').click(function(){$('span#1').stop(true);});
请务必在true
内写下stop()
,表示应停止所有动画。