jQuery .stop() 不起作用,悬停时效果晃动
我有 jQUery 代码:
setInterval(function() {
var grayarrow = jQuery("ul#dropdowngray").parent();
var greenarrow = jQuery("ul#dropdown").parent();
grayarrow.effect('shake', { times:2 }, 100);
greenarrow.effect('shake', { times:3 }, 200);
jQuery("ul#dropdowngray").parent().hover(
function (){ grayarrow.stop().effect('shake', { times:0 }, 100); },
function (){ grayarrow.stop().effect('shake', { times:2 }, 100); }
);
jQuery("ul#dropdown").parent().hover(
function (){ greenarrow.stop().effect('shake', { times:0 }, 100); },
function (){ greenarrow.stop().effect('shake', { times:2 }, 100); }
);
}, 5000);
但是,当我将鼠标悬停在该元素上时,晃动继续执行。最初,我有代码:
jQuery("ul#dropdowngray").parent().hover(
function (){ grayarrow.stop(); },
function (){ grayarrow.stop(); }
);
但是,由于这也不起作用,我实现了此处讨论的解决方案: jquery 。 stop() 不起作用
当鼠标悬停在晃动元素上时,如何有效地使晃动停止?
谢谢你,
I have jQUery code:
setInterval(function() {
var grayarrow = jQuery("ul#dropdowngray").parent();
var greenarrow = jQuery("ul#dropdown").parent();
grayarrow.effect('shake', { times:2 }, 100);
greenarrow.effect('shake', { times:3 }, 200);
jQuery("ul#dropdowngray").parent().hover(
function (){ grayarrow.stop().effect('shake', { times:0 }, 100); },
function (){ grayarrow.stop().effect('shake', { times:2 }, 100); }
);
jQuery("ul#dropdown").parent().hover(
function (){ greenarrow.stop().effect('shake', { times:0 }, 100); },
function (){ greenarrow.stop().effect('shake', { times:2 }, 100); }
);
}, 5000);
To see the effect: http://mainstreetfinancing.com.s136249.gridserver.com/frequently-asked-questions-direct-lender-net-lender.html
However, when I hover over the element, the shaking continues to execute. Originally, I had code:
jQuery("ul#dropdowngray").parent().hover(
function (){ grayarrow.stop(); },
function (){ grayarrow.stop(); }
);
BUT, since this was not working either, I implemented the solution discussed here: jquery .stop() not working
How can I effectively make the shaking stop when the mouse is over the shaking element?
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要立即停止,您需要将 2 个参数(clearQueue:true、jumpToEnd:true)传递到 stop() 调用中,请参阅 http ://api.jquery.com/stop/。此外,您还应该设置一个变量来控制 setInterval 调用,以便当您将鼠标悬停在元素上时,它应该立即返回。这是代码。要查看效果,请访问 http://jsfiddle.net/BT4bt/
To stop immediately you need to pass 2 argements (clearQueue:true, jumpToEnd:true) into stop() call, see http://api.jquery.com/stop/. Also you should set a variable to control the setInterval call so that when you mouse is hovered on the element it should return immediately. Here is the code. To see the effect, go to http://jsfiddle.net/BT4bt/