kiltjs / jqlite

Tiny JavaScript DOM query library that uses pure CSS selectors
MIT License
99 stars 19 forks source link

Style change event detection #29

Closed RongBranovate closed 8 years ago

RongBranovate commented 9 years ago

Hi @jgermade.

I have an element with a width in %, i'm trying to get a listener on that element that would fire when it gets re-sized.

I thought about using MutationObserver but i need to keep it IE9 supported.

I saw this question, and what he answered in the question. I was wandering, won't it screw-up the css function all togather?

This is what he wrote:

(function() {
    var ev = new $.Event('style'),
        orig = $.fn.css;
    $.fn.css = function() {
        $(this).trigger(ev);
        return orig.apply(this, arguments);
    }
})();

This will temporary override the internal prototype.css method and the redefine it with a trigger at the end.

But i'm not sure that's what i need.... any idea?

jgermade commented 9 years ago

Hi @RongBranovate , I understand that what you need is detect when an element is resized in px. But when window is resized element may be already resized too but width property value does not change.

Maybe you can watch window resize, and check element size change. This may help you: http://plnkr.co/edit/s4Qul9ydoAbqyBpX0hAH?p=preview