'Event for resize stopped

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.



Solution 1:[1]

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

function onResize(){ ... }

var timer;

$(window).bind('resize', function(){
    if (timer) {
        clearTimeout(timer);
    }

    timer = setTimeout(onResize, 100);
});

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

Solution 2:[2]

You can try this :

function rsizeItems() 
{ }

var tOut = false;
var milSec = 500;
$(window).resize(function(){
 if(tOut !== false)
    clearTimeout(tOut);
 tOut = setTimeout(rsizeItems, milSec);
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Spooky
Solution 2 Marc Uberstein