Answer the question
In order to leave comments, you need to log in
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!'); // и тут показывается алерт
Answer the question
In order to leave comments, you need to log in
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).
jQuery has event resize
Example:
$(window).resize(function() {
$('#log').append('<div>Handler for .resize() called.</div>');
});
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).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question