3

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?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
hh54188
  • 14,027
  • 31
  • 107
  • 178

2 Answers2

1

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'
Community
  • 1
  • 1
vol7ron
  • 38,313
  • 20
  • 110
  • 168
0

you can use Jquery .resize( handler(eventObject) ) executed on window resize:

 $(window).resize(function() {
     $('#log').append('<div>Handler for .resize() called.</div>');
 });
juhan_h
  • 3,865
  • 3
  • 29
  • 35