Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I catch element's resize event? [duplicate]

I know I can let one element resize through css3 resize property:

resize: both;
overflow: auto

but can I catch the resize event? like:

element.addEventListener('resize', fn, false);

I try this, but it doesn't work, is there other way to do this kind of job?

like image 643
hh54188 Avatar asked Mar 31 '26 17:03

hh54188


1 Answers

As per this answer, you may try:

var addEvent = function(elem, type, eventHandle) {
    if (elem == null || elem == undefined) return;
    if ( elem.addEventListener ) {
        elem.addEventListener( type, eventHandle, false );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( "on" + type, eventHandle );
    } else {
        elem["on"+type]=eventHandle;
    }
};

Called:

addEvent(element, 'resize', fn);    // you may want to try 'onresize'
like image 109
vol7ron Avatar answered Apr 03 '26 07:04

vol7ron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!