当前位置:网站首页>Anti shake and throttling of JS
Anti shake and throttling of JS
2022-07-23 11:18:00 【Vivqst】
Shake proof : High frequency triggered events , After triggering the event n Execute the function once per second , if n Second event triggers again , Then restart the calculation of time
Use scenarios : Query while entering the search box , Optimized query , Query after input stops
function debounce(fn, delay) {
var timeout = null
return function(){
if(timeout) clearTimeout(timeout)
timeout = setTimeout(() => {
// Change in strict mode this The direction of
fn.apply(this, arguments)
}, delay)
}
}
function handle() {
console.log(' Execution event ')
}
window.addEventListener('scroll', debounce(handle, 1000))
throttle : High frequency triggered events , every other n Execute the function once per second , Dilutes the frequency of executing the function
Use scenarios : Listen for scrollbar scrolling Events , When scrolling, add some styles or animation effects to the elements according to the height of scrolling
function throttle(fn, delay) {
var timeout = null
return function(){
if(timeout) return false
timeout = setTimeout(() => {
fn.apply(this, arguments)
clearTimeout(timeout)
timeout = null
}, delay)
}
}
function handle() {
console.log(' Execution event ')
}
window.addEventListener('scroll', throttle(handle, 1000))
边栏推荐
- [python flask notes 5] blueprint is easy to use
- Master slave synchronization step read / write separation + self encountered error sharing
- shell/sh/bash的区别和基本操作
- Celery异步发送短信
- 高阶函数的应用:手写Promise源码(一)
- General view, serializer
- Pywinauto+某应用程序(学习至第9讲)--受阻
- Install pyGame using CMD
- 【无标题】
- Web server failed to start. Port 8080 was already in use.
猜你喜欢
随机推荐
Partial usage of C #
JDBC database connection pool
分页、过滤
Redis database and project framework
Scattered notes of machine learning: some concepts and notes
js高阶函数
请求数据获取与响应
【6.28】
MySQL syntax (pure syntax)
通用视图,序列化器
Sequencing, current limiting
Project process summary
py程序可以运行,但打包出的exe运行提示错误:加载“cv2”二进制扩展时检测到递归。请检查OpenCV安装。
check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ord
img标签设置height和width无效
Keras保存训练过程中的最好模型
slice()和splice()区别
Flask蓝图
对NLP中transformer里面decoder的理解
Paging and filtering
![[pytho-flask筆記5]藍圖簡單使用](/img/0a/00b259f42e2fa83d4871263cc5f184.png)





