gpt4 book ai didi

Javascript动画图片,向上滑动bug

转载 作者:行者123 更新时间:2023-11-30 10:21:07 25 4
gpt4 key购买 nike

我有一个滑动图像,但我遇到了问题。如果您多次将鼠标快速悬停在图像上,然后将鼠标移到图片之外,它仍然会动画。即使您没有将鼠标悬停在动画上,它也会以某种方式录制和播放动画。这是我的代码和 link检查它:

<script type="text/javascript">
$(document).ready(function() {
$('.col-md-4,.col-xs-4').hover(
function () {
$(this).find('#hoverpic').animate({ "top": "-=330px" }, "normal" );
},
function () {
$(this).find('#hoverpic').animate({ "top": "+=330px" }, "normal" );
});
});
</script>

最佳答案

添加.stop()

   function () {
$(this).find('#hoverpic').stop().animate({ "top": "-=330px" }, "normal" );
},
function () {
$(this).find('#hoverpic').stop().animate({ "top": "+=330px" }, "normal" );
});

如果 .stop() 不够好

您可以尝试使用 .stop(true).stop(true, true)

http://api.jquery.com/stop

关于Javascript动画图片,向上滑动bug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21392437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com