jQuery UI 可调整大小的火窗口调整大小事件
我有 2 个事件,一个用于检测窗口大小调整,另一个用于检测 div 的可调整大小的停止。
但是当我调整 div 大小时,在控制台中检测到窗口调整大小事件。
有什么办法可以阻止这个吗?
$(document).ready(function(){
$(window).bind('resize', function(){
console.log("resize");
});
$(".a").resizable();
});
I have 2 events, one to detect window resize and other to detect the resizable stop of div.
But when I resize the div, in the console detect the window resize event.
Is there any way to block this?
$(document).ready(function(){
$(window).bind('resize', function(){
console.log("resize");
});
$(".a").resizable();
});
Example: http://jsfiddle.net/qwjDz/1/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
所有这些答案都没有帮助。问题是调整大小事件会冒泡到窗口。因此,即使调整大小发生在 div 上,最终 e.target 也将是窗口。所以真正的答案是停止传播调整大小事件:
All of these answers are not going to help. The issue is that resize event bubbles up to the window. So eventually the e.target will be the window even if the resize happened on the div. So the real answer is to simply stop propagating the resize event:
您会看到此行为是由于事件冒泡。一种解决方法:使用
event.target
检查回调中的事件源:演示:http://jsfiddle .net/mattball/HEfM9/
另一个解决方案是向可调整大小的对象添加一个(编辑:这应该有效,但由于某种原因不起作用:http: //jsfiddle.net/mattball/5DtdY。)resize
处理程序,并停止事件在 DOM 树上的传播(即“冒泡”)。You see this behavior because of event bubbling. One workaround: check the source of the event in the callback using
event.target
:Demo: http://jsfiddle.net/mattball/HEfM9/
Another solution is to add a(Edit: this should work, but for some reason does not: http://jsfiddle.net/mattball/5DtdY.)resize
handler to the resizable and stop the event's propagation up the DOM tree (that's the "bubbling").我认为实际上最安全的方法是执行以下操作:
I think that actually the safest would be to do the following:
对我来说,对于 JQuery 1.7.2,这里提出的解决方案都不起作用。因此,我必须想出一个稍微不同的浏览器,它可以在较旧的 IE 浏览器以及 Chrome 上运行...
如果调整大小的元素不是
,则可能需要进行调整
For me, with JQuery 1.7.2 none of the solution proposed here worked. So I had to come up with a slightly different one that works on older IE browsers as well as Chrome...
This might have to be adapted if the element resized is something else than a
<div>
http://bugs.jqueryui.com/ticket/7514
http://bugs.jqueryui.com/ticket/7514