我编写了这个 jQuery 代码,但是当我试图在动画元素返回到其原始位置(使用回调函数)时停止它时,它没有响应,但它变得更慢! 。 我使用的是jquery-1.6.4版本
<script type="text/javascript">
$(function () {
$("#right").click(function () {
$(".theDiv0").animate({ left: "800px" }, 2000, "swing", returnToLeft);
$(".theDiv1").animate({ left: "800px" }, 2000, "linear", returnToLeft);
});
function returnToLeft() {
$(".theDiv0").animate({ left: "10px" }, 2000, "swing");
$(".theDiv1").animate({ left: "10px" }, 2000, "linear");
}
$("#stop").click(function () {
$(".theDiv0,.theDiv1").stop();
});
});
</script>
有什么建议/解决方案吗?
最佳答案
尝试使用.stop(true)
请参阅docs欲了解更多信息。如果我是对的,这确实应该停止动画。
关于jquery - 为什么 stop() 函数不能正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8010564/