当前位置:网站首页>防抖和节流
防抖和节流
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
边栏推荐
- 反思 | 事件总线的局限性,组件化开发流程中通信机制的设计与实现
- Redis connection error err auth < password > called without any password configured for the default user
- npm 安装踩坑
- js之预解析
- int a = 1存放在哪
- ABAP 实现发布RESTful服务供外部调用示例
- Thorough inquiry -- understanding and analysis of cocos2d source code
- 数据分析入门 | kaggle泰坦尼克任务(三)—>探索数据分析
- Mobile game performance optimization
- js之自定义属性以及H5中如何判断自定义属性
猜你喜欢

keytool: command not found

SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)

Date对象(js内置对象)

SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)

h5本地存储数据sessionStorage、localStorage

Design optimization of MySQL database

js之什么是事件?事件三要素以及操作元素

Authorization server (simple construction of authorization server)

SAP PI/PO功能运行状态监控检查

On BFC (block formatting context)
随机推荐
刨根问底---cocos2d源码的理解与分析
js之什么是事件?事件三要素以及操作元素
Authorization server (simple construction of authorization server)
Reflection on the systematic design of Android audio and video caching mechanism
js之作用域、作用域链、全局变量和局部变量
4. Multi table query
P1446 [HNOI2008]Cards(Burnside定理+dp计数)
SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
Moment.js中format方法函数的格式
Mobile game performance optimization
js之函数的两种声明方式
[Ted series] how does a habit change my life
数论分块(整除分块)
9. Common functions
13.用户和权限管理
CSDN很火的汤小洋老师全部课程总共有哪些(问号问号问号)
keytool: command not found
js之DOM学习获取元素
js之自定义属性以及H5中如何判断自定义属性
常用的DOS命令