窗口上的Javascript调整大小结束 [英] Javascript on window resize end
本文介绍了窗口上的Javascript调整大小结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在调整窗口大小时调用一个函数:
I am calling a function when the window is resized like this:
window.addEventListener("resize", calculateDimensions());
但是我需要一种方法在调整窗口大小后调用不同的函数。
有没有办法用本机js(而不是jquery)实现这个目标
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
推荐答案
您可以设置超时并在重新调整大小时重置它。因此,最后一次超时未被取消且函数运行:
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);
};
}
可以这样:
window.addEventListener("resize",debounce(function(e){
alert("end of resizing");
}));
这篇关于窗口上的Javascript调整大小结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文