jQuery UI可调整大小的防火窗口调整大小事件

问题描述:

我有2个事件,一个用于检测窗口调整大小,另一个用于检测div的可调整大小的停止。

I have 2 events, one to detect window resize and other to detect the resizable stop of div.

但是当我调整div的大小时,在控制台中检测到窗口调整大小事件。

But when I resize the div, in the console detect the window resize event.

有没有办法阻止这个?

$(document).ready(function(){
     $(window).bind('resize', function(){
        console.log("resize");    
     }); 
     $(".a").resizable();
 });

示例: http://jsfiddle.net/qwjDz/1/

所有这些答案不会有帮助。问题是调整大小事件会向窗口冒泡。所以最终e.target将成为窗口,即使调整大小发生在div上。所以真正的答案是简单地停止传播resize事件:

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:

$("#mydiv").resizable().on('resize', function (e) {
    e.stopPropagation(); 
});