Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event for resize stopped

Tags:

jquery

Is there an event that tells me when the user has stopped resizing by letting go of the mouse button? I'm looking at $(window).resize, and it's firing for every pixel movement. I just need to know when they've stopped.

like image 746
Phillip Senn Avatar asked Mar 21 '11 21:03

Phillip Senn


People also ask

When should I fire the resize event in jQuery?

Firing resize event only when resizing is finished. jQuery resize event is fired when the size of the browser’s window (viewport) changes as pointed out in jQuery documentation. Sometimes we need to execute functions which might take a while to execute or which might consume quite a few resources from the machine.

When is the end of a window resize event?

Well, as far as the window manager is concerned, each resize event is its own message, with a distinct beginning and end, so technically, every time the window is resized, it is the end. Having said that, maybe you want to set a delay to your continuation?

When is the “resize” event fired?

When we resize the browser window, the “resize” event is fired continuously, multiple times while resizing. We want the “resize” event to only be fired once we are done resizing.

What happens if the resize event is triggered too many times?

If the resize event is triggered too many times for your application, see Optimizing window.onresize to control the time after which the event fires. The following example reports the window size each time it is resized.


2 Answers

no, but you can defer the event handler if you want:

function onResize(){ ... }

var timer;
$(window).bind('resize', function(){
   timer && clearTimeout(timer);
   timer = setTimeout(onResize, 100);
});

this will make it fire after the user has stopped resizing for 100ms.

like image 156
Nobody Avatar answered Sep 19 '22 18:09

Nobody


You can try this :

function rsizeItems() 
{ }

var tOut = false;
var milSec = 500;
$(window).resize(function(){
 if(tOut !== false)
    clearTimeout(tOut);
 tOut = setTimeout(rsizeItems, milSec);
});
like image 32
Marc Uberstein Avatar answered Sep 20 '22 18:09

Marc Uberstein