扫码关注官方订阅号
现在有一个需求,在$(window).resize时clearInterval(xxx),然后再resize结束时再给xxx=setInterval(function(){},xxx),如何才能实现?
光阴似箭催人老,日月如移越少年。
var handle; function resize(e) { clearInterval(handle); handle = setInterval(function(){ ...dosomething }, 100); }
var intervalId, timeoutId, interval = 500; $(window).resize(function(){ if(intervalId){ clearInterval(xxx); } timeoutId && clearTimeout(timeoutId); if(!intervalId){ // 如果 500 毫秒内没有执行 resize 事件我们就认为停止 resize 啦 timeoutId = setTimeout(function(){ intervalId = setInterval(function(){}, milliseconds); }, interval) } });
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
光阴似箭催人老,日月如移越少年。