javascript - .animate无限循环

标签 javascript jquery

我对 jQuery .animate 无限循环中断方法的解决方案感兴趣。

$(element).mouseover(function() {
   $(this).animate({ opacity: 1 }, duration, customFunc);
}).mouseout(function() {

});

现在的问题是如何打破这个循环?例如,在 mouseout 事件中?

我可以使用 setIntervalclearInterval 轻松完成,但是有没有办法使用 .animate功能?

最佳答案

使用.stop方法:

http://api.jquery.com/stop/

我假设您想立即停止当前正在运行的动画?

$(element).mouseover(function() {
   $(this).animate({ opacity: 1 }, duration, customFunc);
}).mouseout(function() {
   $(this).stop();
});

关于javascript - .animate无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10200337/

相关文章:

javascript - 在 JSX 文件中导入 css

Javascript:滚动到光标在 contenteditable div 中粘贴

php - 在输入字段中输入字符时自动建议?

javascript - AJAX上传文件为什么要用FormData?

javascript - 未找到 AngularJS 页面。主页已注入(inject)索引模板,但未注入(inject)其他页面

javascript - @@iterator- Javascript - 它到底是什么?

javascript - 防止 WordPress javascript 冲突的好习惯?

javascript - 从 node.js 服务器加载脚本的正确 src= 属性是什么

javascript - 显示 gif 直到内容加载

javascript - Jquery:Ajax 调用返回 JSON 数据的 php 脚本