当前位置:网站首页>[anti shake and throttling]
[anti shake and throttling]
2022-07-27 21:14:00 【Xiaomenong】
Anti shake of events
When a function executes too many times in a certain time , We need to reduce the frequency , If in 200ms The scrolling event is not triggered again within , Execute the function for so long If 220ms The scrolling event is triggered again in the , Then cancel the current timing . Restart the clock . Effect if a large number of scrolls are triggered in a short time, the function will only be executed once . We can use the function /* * Parameters * fn: A function to be executed * delay: Delay time */ function debounce(fn,delay){ // First create a variable to store a timer var timer=null; // The following line of code is closure return function(){ if(timer){ clearTimeout(timer) } timer=setTimeout(fn,delay) } }
The throttling of events
function throttle(fn,delay){
var valid=true;
return function(){
if(!valid){
return valid=true
}
valid=false
setTimeout(function(){
fn();
valid=true;
},2000)
}
}边栏推荐
- What are the application scenarios of real name authentication in the cultural tourism industry?
- 自动化测试----unittest框架
- 常见ArrayLIst面试题
- LeetCode每日一练 —— 21. 合并两个有序链表
- 自定义学习率
- DJI push code (one code for one use, updated on July 26, 2022)
- Command line PDF Converter::: fcoder 2PDF
- Obtain website shell permission based on file upload vulnerability
- 【R语言】【1】初学R语言语法使用Rstudio编辑
- Understanding network model TCPIP model
猜你喜欢

自动化测试----unittest框架

基于文件上传漏洞获得网站 shell 权限

Introduction to source insight 4.0

Automated testing - unittest framework

Installation and use tutorial of the latest version of Web vulnerability scanning tool appscan\awvs\xray

LeetCode每日一练 —— 链表中倒数第 k 个结点

成分句法分析综述(第二版)

NATAPP内网穿透工具外网访问个人项目

“收割”NFT:200元淘宝买图,上链卖30万元
![论文赏析[AAAI18]面向序列建模的元多任务学习](/img/2b/345b5a287fcd9c9b1a86ae683f124b.png)
论文赏析[AAAI18]面向序列建模的元多任务学习
随机推荐
What if the start button doesn't respond after the win11 system updates kb5014668?
LeetCode每日一练 —— 21. 合并两个有序链表
A method of MCU log output
LeetCode每日一练 —— CM11 链表分割
LeetCode每日一练 —— 203. 移除链表元素
Force deduction solution summary 592 fraction addition and subtraction
Differences among native objects, built-in objects, and host objects
Automated testing ----- selenium (II)
Qt OPenGL 光的漫反射
AIRIOT答疑第6期|如何使用二次开发引擎?
Know the transmission medium, the medium of network communication
R language uses LM function to build multiple linear regression model, writes regression equation according to model coefficient, and uses deviance function to calculate the sum of squares of residual
QT link MSSQL
访问共享文件夹时提示“因为文件共享不安全 SMB1协议”请使用SMB2协议
IOU target tracking II: viou tracker
mysql 最大建议行数2000w,靠谱吗?
js闭包知识
PHP code audit 5 - XSS vulnerability
Ue5 uses DLSS (super sampling) to improve the FPS of the scene away from the optimization scheme of Caton
Leetcode daily practice 206. Reverse the linked list