Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  165] [ 6]  / answers: 1 / hits: 26557  / 7 Years ago, sun, august 27, 2017, 12:00:00

I am calling a function when the window is resized like this:



window.addEventListener(resize, calculateDimensions());


But I need a way to call a different function AFTER the window has been resized.
Is there any way to achieve this using native js (not jquery)



TIA


More From » resize

 Answers
3

You could set a Timeout and reset it when resize is fired again. So the last timeout isnt canceled and the function is run:



function debounce(func){
var timer;
return function(event){
if(timer) clearTimeout(timer);
timer = setTimeout(func,100,event);
};
}


Usable like this:



window.addEventListener(resize,debounce(function(e){
alert(end of resizing);
}));

[#56648] Tuesday, August 22, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sabinal

Total Points: 144
Total Questions: 112
Total Answers: 107

Location: Ghana
Member since Mon, Aug 22, 2022
2 Years ago
;