当前位置:网站首页>Use of anti shake debounce and throttling throttle
Use of anti shake debounce and throttling throttle
2022-07-19 04:04:00 【666 sign】
Anti shake function : stay n Only the last time in seconds ( After triggering an event , Before the next trigger , If the intermediate interval exceeds the set time, the request will be sent , If it is triggered all the time, the request will not be sent )
Application scenarios : Button to submit Events , Search function , Browser window zoom , Form validation ,scroll Event scrolling ,resize event
/**
* Shake proof (n Only the last time in seconds )
* @param fn
* @param delay
* @return {Function}
* @private
*/
export function _debounce(fn, delay) {
var newDelay = delay || 500;
var timer;
return function () {
var args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
timer = null;
fn.apply(this, args);
}, newDelay);
};
} Throttling function : stay n Only once per second ( If you continue to trigger an event , Is every n Once per second )
Application scenarios : Drag and drop , Distance of mouse movement , monitor scroll Scroll Events
/**
* throttle ( every other n Once per second )
* @param fn
* @param interval
* @return {Function}
* @private
*/
export function _throttle(fn, interval) {
var last;
var timer;
var newInterval = interval || 200;
return function () {
var th = this;
var args = arguments;
var now = +new Date();
if (last && now - last < newInterval) {
clearTimeout(timer);
timer = setTimeout(function () {
last = now;
fn.apply(th, args);
}, newInterval);
} else {
last = now;
fn.apply(th, args);
}
};
}Use :
// Click confirm to submit the payment order
confirmSubmit () {
this._debounce(this.action, 1000)();
}
边栏推荐
- 掩饰性治疗
- Program analysis and Optimization - 11 multi branch analysis
- How to do clear scanning: try scanning tailor scantailor advanced | including the usage of scantailor
- 软件测试-进阶篇
- Codeforces Round #807 (Div. 2) A~D
- Matlab drawing activation function sigmoid, relu
- 7.16模拟赛总结
- Raspberry pie configuration
- 《创业实践模拟》课程教学改革及软件平台
- Redis數據遷移方法三
猜你喜欢
![[Paper Abstract] screenshots of methods for recording abstracts of interest and papers in special fields.](/img/61/aeda90fd5c5a055ea8032027aa7a98.png)
[Paper Abstract] screenshots of methods for recording abstracts of interest and papers in special fields.

初识ESP8266(二)————搭建网络服务器实现远程控制

Group 卷积

XDC 2022 Intel 技术专场:英特尔软硬件技术构筑云计算架构基石
![[untitled]](/img/3b/fb86cb1512c2dbe3626bb50b990e44.png)
[untitled]

程序分析与优化 - 11 多分支分析

第2章——创建与维护MySQL数据库

Asp.NetCore 中使用grpc

Workload-Aware Performance Tuning for Autonomous DBMSs

The role of key in V-for
随机推荐
micro、M3O微服务系列(三)
AcWing:第60场周赛
要想组建敏捷团队,这些方法不可少
Tutorial: Adaptive Replication and Partitioning in Data Systems
Chapter 2 - create and maintain MySQL database
Modify jar package content
Get to know esp8266 (II) -- build a network server to realize remote control
【RuoYi-Vue-Plus】学习笔记 30 - Redisson(六) 有界阻塞队列 Bounded Blocking Queue(Redisson 源码 + Lua 脚本)
Redis数据迁移:方法二AOF
Swagger
Tutorial: Adaptive Replication and Partitioning in Data Systems
针孔微创牙龈手术(Pinhole Gum Rejuvenation)
Sword finger offer 60 Points of N dice
库函数的模拟实现
Group convolution
Mathematical modeling learning (67): detailed introduction to xgboost classification model case tutorial
Redis Data Migration Method III
dapr系列(一)
《创业实践模拟》课程教学改革及软件平台
Idea configures SFTP and SSH, which is very convenient to deploy and locate error logs