So I currently use something like:
$(window).resize(function(){resizedw();});
But this gets called many times while resizing process goes on. Is it possible to catch an event when it ends?
So I currently use something like:
$(window).resize(function(){resizedw();});
But this gets called many times while resizing process goes on. Is it possible to catch an event when it ends?
There is an elegant solution using the Underscore.js So, if you are using it in your project you can do the following -
This should be enough :) But, If you are interested to read more on that, you can check my blog post -
http://rifatnabi.com/post/detect-end-of-jquery-resize-event-using-underscore-debounce(deadlink)i wrote a litte wrapper function on my own...
Here is the usage:
Here is VERY simple script to trigger both a 'resizestart' and 'resizeend' event on the window object.
There is no need to muck around with dates and times.
The
d
variable represents the number of milliseconds between resize events before triggering the resize end event, you can play with this to change how sensitive the end event is.To listen to these events all you need to do is:
resizestart:
$(window).on('resizestart', function(event){console.log('Resize Start!');});
resizeend:
$(window).on('resizeend', function(event){console.log('Resize End!');});
I wrote a function that passes a function when wrapped in any resize event. It uses an interval so that the resize even isn't constantly creating timeout events. This allows it to perform independently of the resize event other than a log entry that should be removed in production.
https://github.com/UniWrighte/resizeOnEnd/blob/master/resizeOnEnd.js
}
You can store a reference id to any setInterval or setTimeout. Like this:
To do this without a "global" variable you can add a local variable to the function itself. Ex: