jQuery - 如何使用 stopPropagation()
我以前做过这个,但我很难让它工作...
我需要以下 jquery 具有 .stopPropagation 函数,这样如果用户将鼠标悬停在三个元素上太快,动画就不会变得疯狂!
$(function () {
var tabContainers = $('div.subMenu > div');
tabContainers.hide();
$('.mainMenuDiv a').hover(
function (e) {
tabContainers.filter(this.hash).slideDown();
e.stop();
},
function(e){
tabContainers.filter(this.hash).slideUp();
e.stopPropagation();
});
});
I've done this before, but I'm having trouble getting this to work...
I need the following jquery to have a .stopPropagation function, so the animation won't go crazy if the user hovers over three elements too quickly!
$(function () {
var tabContainers = $('div.subMenu > div');
tabContainers.hide();
$('.mainMenuDiv a').hover(
function (e) {
tabContainers.filter(this.hash).slideDown();
e.stop();
},
function(e){
tabContainers.filter(this.hash).slideUp();
e.stopPropagation();
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来您正在寻找
stop
函数来取消任何不完整的动画。或者如果您希望“回滚”任何正在进行的动画,请尝试:
查看 文档了解更多信息。
Sounds like you are looking for the
stop
function that cancels any incomplete animations.or if you'd like any in-progress animation(s) to be "rolled back" try:
Check out the docs for more info.
使用 stopPropagation() 和 stopImmediatePropagation() 时要小心,就好像它们是同一件事一样:
Event.stopPropagation() 方法会阻止事件对象移动到下一个节点,但仅限于该节点上的任何其他事件侦听器之后允许当前节点执行。
Event.stopImmediatePropagation() 方法还会阻止事件对象移动到下一个节点,但不允许当前节点上的任何其他事件侦听器执行。
Be carefull when using stopPropagation() and stopImmediatePropagation() as if they were the same thing:
The Event.stopPropagation() method prevents the event object from moving on to the next node, but only after any other event listeners on the current node are allowed to execute.
The Event.stopImmediatePropagation() method also prevents the event object from moving on to the next node, but does not allow any other event listeners on the current node to execute.
希望这有帮助。 ;) 事件从子元素“冒泡”到其所有父元素,您可以使用
event.stopPropragation();
或event.stopImmediatePropagation()
。然而,要停止动画,您需要dequeue()
。Hope that this helps. ;) Events “bubble up” from the child element to all its parents, and you would
event.stopPropragation();
orevent.stopImmediatePropagation()
. However to stop animation youdequeue()
.我可能是错的,但这可能有效:
I could be wrong, but this might work: