当前位置:网站首页>防抖和节流
防抖和节流
2022-04-23 06:26:00 【笔描相思】
防抖:解决的问题就是在一段时间间隔内多次触发事件的时候,只会执行一次
节流:解决的问题是减少一段时间的触发频率
1:函数在指定时间内只会触发一次,具体实现方法
第一次触发函数的时候,延迟delay时间执行,如果在delay时间段内再次触发该函数,则重新开始
计时
如果delay时间段内没有触发该函数,则执行该函数
function bunde(fn ,depaly)
{
let timetar=null;
return function()
{
if(timetar)
{
clearTimeout(timetar);
}
timetar=setTimeout(fn,depaly);
}
}
节流:
防抖的问题是,在短时间内不断触发事件,回调函数永远不会执行。
节流的思想:在短时间内不断触发事件,回调函数只会在指定间隔时间内执行。
function throttle(fn, delay) {
let timer = null;
return function() {
if (timer) return false
timer = setTimeout(() => {
fn()
timer = null
}, delay)
}
}
版权声明
本文为[笔描相思]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44788119/article/details/120902466
边栏推荐
猜你喜欢
反思 | 事件总线的局限性,组件化开发流程中通信机制的设计与实现
SAP pi / PO rfc2soap publishes RFC interface as WS example
设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
ABAP 实现发布RESTful服务供外部调用示例
SAP CR传输请求顺序、依赖检查
redis连接出错 ERR AUTH <password> called without any password configured for the default user.
页面实时显示当前时间
Date对象(js内置对象)
On BFC (block formatting context)
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
随机推荐
9.常用函数
10.更新操作
Mobile game performance optimization
13. User and authority management
js之自定义属性以及H5中如何判断自定义属性
On BFC (block formatting context)
H5 case development
int a = 1存放在哪
js之DOM学习获取元素
keytool: command not found
数组扁平化
数论分块(整除分块)
ABAP 从CDS VIEW 发布OData Service示例
Processing of common dependency module
Hot change scheme and dynamic update strategy of mobile game
[2020WC Day2]F.采蘑菇的克拉莉丝(子树和查询、轻重儿子思想)
7.子查询
3. Sort statement
typescript字典的使用
11. Table and library management