当前位置:网站首页>【防抖与节流】
【防抖与节流】
2022-07-27 18:08:00 【逍码农】
事件的防抖
当一个函数在一定的事间内执行的次数太高了,我们就需要降低频率,如果在200ms以内没有再次触发滚动事件,那么久执行次函数 如果220ms内再次触发滚动事件,那么取消当前计时。重新开始计时。效果如果短时间内大量触发滚动只会执行一次函数 。我们可以用一下函数 /* * 参数 * fn:一个要执行的函数 * delay:延迟的时间 */ function debounce(fn,delay){ //首先创建一个变量来存储一个定时器 var timer=null; //下面这一行代码是闭包 return function(){ if(timer){ clearTimeout(timer) } timer=setTimeout(fn,delay) } }
事件的节流
function throttle(fn,delay){
var valid=true;
return function(){
if(!valid){
return valid=true
}
valid=false
setTimeout(function(){
fn();
valid=true;
},2000)
}
}边栏推荐
- Office automation solution - docuware cloud is a complete solution to migrate applications and processes to the cloud
- adb shell ls /system/bin(索引表)
- 金仓数据库 KingbaseES 异构数据库移植指南 (4. 应用迁移流程)
- Redis hash structure command
- 软件测试面试题:已知一个数字为1,如何输出“0001
- What is a multi-layer perceptron (what is a multi-layer perceptron)
- Interviewer: what is the abstract factory model?
- 用户和权限限制用户使用资源
- Software test interview question: if a string is known as "hello_world_yoyo", how to get a queue ["hello", "world", "yoyo"]
- Advanced SQL skills CTE and recursive query
猜你喜欢
![[rctf2015]easysql-1 | SQL injection](/img/69/aa1fc60ecf9a0702d35d876e8c3dda.png)
[rctf2015]easysql-1 | SQL injection

Mlx90640 infrared thermal imager temperature sensor module development notes (VII)

Data warehouse construction - DWD floor
![[hierarchical reinforcement learning] HAC paper and code](/img/f5/d5f791d0f9da749eafa912be9dfbb5.png)
[hierarchical reinforcement learning] HAC paper and code

IM即时通讯开发如何提升移动网络下图片传输速度和成功率

Understand the wonderful use of dowanward API, and easily grasp kubernetes environment variables

未定义变量 “Lattice“ 或类 “Lattice.latticeEasy“(Matlab)
![Leetcode:1498. Number of subsequences that meet the conditions [sort + bisection + power hash table]](/img/a9/de68e8affcb6b84e82cf344e7254e3.png)
Leetcode:1498. Number of subsequences that meet the conditions [sort + bisection + power hash table]

When adding RTSP devices to easycvr platform, what is the reason for the phenomenon that they are all connected by TCP?

一周活动速递|深入浅出第8期;Meetup成都站报名进行中
随机推荐
关于栈迁移的那些事儿
一个程序员的水平能差到什么程度?
access control
Babbitt | metauniverse daily must read: Tencent News suspended the sales service of digital collections, users left messages asking for a "refund", and phantom core also fell into the dilemma of "unsa
面了个腾讯拿38K跳槽出来的,见识到了真正的测试天花板
My approval of OA project (Query & meeting signature)
MySQL驱动jar包的下载--保姆教程
Software test interview question: if a string is known as "hello_world_yoyo", how to get a queue ["hello", "world", "yoyo"]
How bad can a programmer be?
C language POW function (how to play exponential function in C language)
软件测试面试题:字符串 “axbyczdj“,如果得到结果“abcd
openresty lua-resty-core 使用
Redis basic understanding, five basic data types
Flask-MDict搭建在线Mdict词典服务
Users and permissions revoke user permissions
Preprocessing and macro definition
一周活动速递|深入浅出第8期;Meetup成都站报名进行中
【阿里安全 × ICDM 2022】20万奖金池!大规模电商图上的风险商品检测赛火热报名中!...
DP (dynamic programming)
Advanced SQL skills CTE and recursive query