当前位置:网站首页>《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
2022-07-07 10:07:00 【InfoQ】
写在前面
防抖篇
*防抖小故事
*防抖逻辑图

*防抖代码实现
setTimeout
setTimeout
setTimeout
setTimeout
setTimeout
setTimeout
// 防抖初始变量
let debouncTtimeout
// 点击防抖按钮触发函数
function debounce() {
clearTimeout(debouncTtimeout)
debouncTtimeout = setTimeout(function () {
console.log("执行防抖操作啦~")
}, 3000)
}
节流篇
*节流小故事
*节流逻辑图

*节流代码实现
// 节流初始时间戳
let pastDate = new Date().valueOf()
// 点击节流按钮触发函数
function throttle() {
let nowDate = new Date().valueOf()
if (nowDate - pastDate > 3000) {
console.log('执行节流操作啦~')
pastDate = new Date().valueOf()
}
}
总结
写在后面
边栏推荐
- 顶级域名有哪些?是如何分类的?
- HCIA复习整理
- <No. 8> 1816. Truncate sentences (simple)
- 问下flinkcdc2.2.0的版本,支持并发,这个并发是指多并行度吗,现在发现,mysqlcdc全
- Present pod information to the container through environment variables
- Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
- Hi3516全系统类型烧录教程
- 让数字管理好库存
- Mastering the new functions of swiftui 4 weatherkit and swift charts
- Onedns helps college industry network security
猜你喜欢
Camera calibration (2): summary of monocular camera calibration
【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】
MATLAB實現Huffman編碼譯碼含GUI界面
Talk about SOC startup (11) kernel initialization
Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
Test the foundation of development, and teach you to prepare for a fully functional web platform environment
5V串口接3.3V单片机串口怎么搞?
Up meta - Web3.0 world innovative meta universe financial agreement
<No. 9> 1805. 字符串中不同整数的数目 (简单)
竟然有一半的人不知道 for 与 foreach 的区别???
随机推荐
SwiftUI 教程之如何在 2 秒内实现自动滚动功能
通过环境变量将 Pod 信息呈现给容器
一起探索云服务之云数据库
The Oracle message permission under the local Navicat connection liunx is insufficient
112.网络安全渗透测试—[权限提升篇10]—[Windows 2003 LPK.DDL劫持提权&msf本地提权]
Flet教程之 15 GridView 基础入门(教程含源码)
sql里,我想设置外键,为什么出现这个问题
Unity中SmoothStep介绍和应用: 溶解特效优化
Solve the problem that vscode can only open two tabs
Let digital manage inventory
Swiftui tutorial how to realize automatic scrolling function in 2 seconds
Various uses of vim are very practical. I learned and summarized them in my work
About how to install mysql8.0 on the cloud server (Tencent cloud here) and enable local remote connection
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
How much do you know about excel formula?
The road to success in R & D efficiency of 1000 person Internet companies
Rationaldmis2022 array workpiece measurement
C#中在路径前加@的作用