当前位置:网站首页>防抖和节流
防抖和节流
2022-04-23 06:26:00 【笔描相思】
防抖:解决的问题就是在一段时间间隔内多次触发事件的时候,只会执行一次
节流:解决的问题是减少一段时间的触发频率
1:函数在指定时间内只会触发一次,具体实现方法
第一次触发函数的时候,延迟delay时间执行,如果在delay时间段内再次触发该函数,则重新开始
计时
如果delay时间段内没有触发该函数,则执行该函数
function bunde(fn ,depaly)
{
let timetar=null;
return function()
{
if(timetar)
{
clearTimeout(timetar);
}
timetar=setTimeout(fn,depaly);
}
}
节流:
防抖的问题是,在短时间内不断触发事件,回调函数永远不会执行。
节流的思想:在短时间内不断触发事件,回调函数只会在指定间隔时间内执行。
function throttle(fn, delay) {
let timer = null;
return function() {
if (timer) return false
timer = setTimeout(() => {
fn()
timer = null
}, delay)
}
}

版权声明
本文为[笔描相思]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44788119/article/details/120902466
边栏推荐
- 14.事务处理
- SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)
- Educational Codeforces Round 81 (Rated for Div. 2)
- 1.查看数据库和表
- 1. View databases and tables
- redis连接出错 ERR AUTH <password> called without any password configured for the default user.
- 2022.3.14 阿里笔试
- 8.分页查询
- Redis connection error err auth < password > called without any password configured for the default user
- 图论入门——建图
猜你喜欢

js之什么是事件?事件三要素以及操作元素

SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)

Reflection on the systematic design of Android audio and video caching mechanism

简易随机点名抽奖(js下编写)

Ogldev reading notes

页面动态显示时间(升级版)

设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?

反思 | Android 音视频缓存机制的系统性设计

SAP pi / PO rfc2soap publishes RFC interface as WS example

SAP PI/PO Soap2Proxy 消费外部ws示例
随机推荐
[CodeForces - 208E] Blood Cousins(k代兄弟问题)
Nacos/sentinel网关限流和分组 (代码)
【TED系列】如何与内心深处的批评家相处?
Date对象(js内置对象)
11.表和库的管理
1. View databases and tables
Game assisted script development journey
数据库查询优化的方式
3.排序语句
MySQL storage engine
Authorization+Token+JWT
判断字符串首尾是否包含目标参数:startsWith()、endsWith()方法
BTREE, B + tree and hash index
Visualization Road (IX) detailed explanation of arrow class
1D/1D动态规划学习总结
Authorization server (simple construction of authorization server)
王者荣耀-unity学习之旅
积性函数与迪利克雷卷积
11. Table and library management
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)