How can I make it so that each time when user changes the window size, the page perform a function?
The following function should do what you need, it works on all browsers (with the single exception of not firing when Safari is NOT maximized and resolution changes)
It fires upon window re-sizing as well as resolution change and also has a delay to avoid multiple calls while the user is re-sizing the window.
var resizeTimer;
//Event to handle resizing
$(window).resize(function ()
{
clearTimeout(resizeTimer);
resizeTimer = setTimeout(Resized, 100);
});
//Actual Resizing Event
function Resized()
{
//Your function goes here
};
Testing jsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With