当前位置:网站首页>防抖和节流
防抖和节流
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
边栏推荐
猜你喜欢

SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)

SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)

Authorization+Token+JWT

How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)

SAP PI/PO登录使用及基本功能简介

Nacos / sentinel gateway current limiting and grouping (code)

SAP PI/PO rfc2RESTful 發布rfc接口為RESTful示例(Proxy間接法)

SAP TRANSLATE使用数据对象掩码示例

自定义时间格式(YYYY-MM-DD HH:mm:ss 星期X)

ogldev-读书笔记
随机推荐
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
Django使用mysql数据库报错解决
9. Common functions
js之DOM事件
每日一题 | 曾被反转链表支配的恐惧
反思 | Android 音视频缓存机制的系统性设计
配置npm
Visualization Road (IX) detailed explanation of arrow class
6. Aggregation function and grouping statistics
Use of typescript dictionary
ABAP 实现发布RESTful服务供外部调用示例
[LNOI2014]LCA——树链剖分——多点LCA深度和问题
安装配置淘宝镜像npm(cnpm)
Authorization+Token+JWT
P1446 [HNOI2008]Cards(Burnside定理+dp计数)
7. sub query
斐波拉去动态规划
10. Update operation
SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
2022.3.14 Ali written examination