正在回答 回答被采纳积分+1
1回答
好帮手慕慕子
2020-01-11 10:06:31
同学你好,对于你的问题解答如下:
前面添加stop的作用是:再次点击时,结束上一次没有执行完的动画
animate后面也可以写stop,但是这样写的作用是直接停止了当前animate动画
老师这里下了一个简单的小示例,同学可以测试一下,快速点击按钮,查看效果,帮助自己更好的理解
<html>
<head>
</head>
<body>
<p><button id="start1">Start1 Animation</button><button id="star2">Start2 Animation</button></p>
<div id="box1" style="background:#98bf21;height:100px;width:100px;float:left">
</div>
<div id="box2" style="background:pink;height:100px;width:100px;float:left;">
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script>
$("#start1").click(function () {
$("#box1").stop(true, true).animate({ height: 300 }, "slow");
});
$("#start2").click(function () {
$("#box1").animate({ height: 300 }, "slow").stop(true, true);
});
</script>
</body>
</html>如果我的回答帮助到了你,欢迎采纳,祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星