Tag: 传播

jQuery – 如何使用stopPropagation()

我以前做过这个,但是我无法让它工作…… 我需要以下jquery才能拥有.stopPropagation函数,因此如果用户过快地hover在三个元素上,动画就不会发疯! $(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(); }); });

jQuery:在它们发生之前捕获所有点击事件?

在我的页面上,我有很多响应点击事件的元素。 有时我需要根据某些全局标志来阻止所有点击。 有没有办法在集中的位置进行检查? 现在我在每个事件中检查标志,例如: var canClick = false; // Global flag // Sample click event: $(“#someDiv”).click(function(){ if(!canClick) return; // Some stuff … }); 我想做的是有一个元素在任何其他元素之前捕获所有点击事件。 我尝试在文档上执行此操作,但这些事件仅在其他单击事件之后发生。 例: $(“#someDiv”).click(function(){ console.log(“someDiv click”); }); $(document).click(function(){ console.log(“Document click”); }); // When I click on the someDiv element it prints: > someDiv click > Document click 我还尝试在所有内容之上放置一个全屏div,并使用它来捕获事件,但问题是没有任何点击通过这个全屏div传播。 此外,我不想依赖于创建额外的元素来捕获点击,因为它感觉有点hacky。 我可以覆盖jQuery点击function,以便我可以把我的小支票放在那里吗? 有什么明显的东西我在这里不见了吗? 谢谢你的帮助。

jQuery on()stopPropagation不工作?

我似乎无法让这个停止传播.. $(document).ready(function(){ $(“body”).on(“click”,”img.theater”,function(event){ event.stopPropagation(); $(‘.theater-wrapper’).show(); }); // This shouldn’t fire if I click inside of the div that’s inside of the // `.theater-wrapper`, which is called `.theater-container`, anything else it should. $(“.theater-wrapper”).click(function(event){ $(‘.theater-wrapper’).hide(); }); }); 请参考这个jsfiddle