当前位置:网站首页>[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)
}
}边栏推荐
- Understanding network model overview of network model
- Leetcode daily practice - 203. remove linked list elements
- Win11系统更新KB5014668后点开始按钮没反应怎么办?
- A method of MCU log output
- What if the start button doesn't respond after the win11 system updates kb5014668?
- js闭包知识
- Lidar China's front loading curtain opens, millions of production capacity to be digested
- 论文赏析[EMNLP18]针对自顶向下和中序移进归约成分句法分析的Dynamic Oracles
- 飞信卒于2022:中国移动一手好牌被打烂,5亿用户成“僵尸”
- One article to understand pychar shortcut key
猜你喜欢

js闭包知识

Uncaught SyntaxError: redeclaration of let page

一种比读写锁更快的锁,还不赶紧认识一下

MAPGIS 3D scene rendering technology and Application

Introduction to source insight 4.0

IOU target tracking II: viou tracker

Typoa spelling check: missing dictionary file for Chinese

API gateway introduction

Beijing / Shanghai / Guangzhou / Shenzhen dama-cdga/cdgp data governance certification registration conditions

如何对话CIO/CTO
随机推荐
QT link MSSQL
LeetCode每日一练 —— 206. 反转链表
How to solve the problem when the Microsoft account login of the computer keeps turning around
DJI push code (one code for one use, updated on July 26, 2022)
Second uncle, why is it so hot?
云管平台中租户以及多租户概念简单说明
A method of MCU log output
mcu日志输出的一种方法
Understanding network model TCPIP model
Brief description of tenant and multi tenant concepts in cloud management platform
Custom learning rate
Leetcode-209- subarray with the smallest length
Qt OPenGL 光的漫反射
One article to understand pychar shortcut key
AIRIOT答疑第6期|如何使用二次开发引擎?
ELK太重?试试KFC日志采集
Beijing / Shanghai / Guangzhou / Shenzhen dama-cdga/cdgp data governance certification registration conditions
Hexagon_ V65_ Programmers_ Reference_ Manual(7)
redis cook book.notes.
Elk too heavy? Try KFC log collection