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,195
  • 62
  • 50
  • 120
hh54188
  • 13,085
  • 30
  • 99
  • 174

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
  • 35,981
  • 19
  • 104
  • 164
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,737
  • 3
  • 27
  • 35