jQuery UI可调整大小的防火窗口调整大小事件 [英] jQuery UI resizable fire window resize event

查看:118
本文介绍了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(); 
});

这篇关于jQuery UI可调整大小的防火窗口调整大小事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆