E
E
EvgeniyKirov2011-02-20 00:16:53
JavaScript
EvgeniyKirov, 2011-02-20 00:16:53

Is it possible to use JavaScript (jQuery) to catch the moment of changing the size of any element?

You need something like this:

$('body').heightChanged(function(){<br>
    alert('event');<br>
});<br>
<br>
$('body').append('Hello!'); // и тут показывается алерт


Is it possible to do this?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
[
[email protected]><e, 2011-02-20
@EvgeniyKirov

And why would the height of the element change? Track the cause, not the result.
As an option, of course, you can check every N milliseconds if the height has changed and, if so, then call the function, but such a frequent height calculation can have an extremely negative impact on performance (reflow / repaint).

V
Vas3K, 2011-02-20
@Vas3K

www.w3schools.com/jsref/event_onresize.asp won't work?

K
Kir Shatrov, 2011-02-20
@RazoR_Empire

jQuery has event resize
Example:

$(window).resize(function() {
  $('#log').append('<div>Handler for .resize() called.</div>');
});

M
Max Kuznetsov, 2011-02-20
@pluseg

jQuery: .resize( [ eventData ], handler(eventObject) )
There's a catch:

Code in a resize handler should never rely on the number of times the handler is called. Depending on implementation, resize events can be sent continuously as the resizing is in progress (the typical behavior in Internet Explorer and WebKit-based browsers such as Safari and Chrome), or only once at the end of the resize operation (the typical behavior in Firefox).

In Russian: the handler can be called either once, or continuously during the resizing of the element - it depends on the browser.

A
Anatoly, 2011-02-20
@taliban

I don’t speak for libraries, but you can subscribe to the main changes , then only a timeout.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question