Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: How to call RESIZE event only once it's FINISHED resizing?

How do I call a function once the browser windows has FINISHED resizing?

I'm trying to do it like so, but am having problems. I'm using the JQuery Resize event function:

$(window).resize(function() {   ... // how to call only once the browser has FINISHED resizing? }); 

However, this function is called continuously if the user is manually resizing the browser window. Which means, it might call this function dozens of times in short interval of time.

How can I call the resize function only a single time (once the browser window has finished resizing)?

UPDATE

Also without having to use a global variable.

like image 873
nickb Avatar asked Nov 28 '10 19:11

nickb


People also ask

How to trigger window resize event in jQuery?

In this case, we will use the native JavaScript event 'resize' in order to trigger the resize event as per our convenience. The syntax would be: $(window). trigger('resize'); $(<element>).

What is resize () function in jQuery?

jQuery resize() MethodThe resize event occurs when the browser window changes size. The resize() method triggers the resize event, or attaches a function to run when a resize event occurs.

What is Resize event in JavaScript?

The resize event fires when the document view (window) has been resized. This event is not cancelable and does not bubble. In some earlier browsers it was possible to register resize event handlers on any HTML element.


1 Answers

Here is an example using thejh's instructions

You can store a reference id to any setInterval or setTimeout. Like this:

var loop = setInterval(func, 30);  // some time later clear the interval clearInterval(loop); 
like image 76
Zevan Avatar answered Oct 03 '22 23:10

Zevan