jQuery UI resizable fire window resize event

后端 未结 5 668
庸人自扰
庸人自扰 2020-12-14 07:41

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.

5条回答
  •  轮回少年
    2020-12-14 08:10

    You see this behavior because of event bubbling. One workaround: check the source of the event in the callback using event.target:

    $(window).bind('resize', function(event) {
        if (!$(event.target).hasClass('ui-resizable')) {
            console.log("resize");
        }
    });
    

    Demo: http://jsfiddle.net/mattball/HEfM9/


    Another solution is to add a resize handler to the resizable and stop the event's propagation up the DOM tree (that's the "bubbling"). (Edit: this should work, but for some reason does not: http://jsfiddle.net/mattball/5DtdY.)

提交回复
热议问题