From ec2e791df60b9eb8832dfc471e8cedd204d30959 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 6 May 2024 14:58:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=E9=98=B2=E6=8A=96=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=B7=BB=E5=8A=A0=E9=A6=96=E6=AC=A1=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/防抖.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/js/防抖.js b/js/防抖.js index a85e191..03d0561 100644 --- a/js/防抖.js +++ b/js/防抖.js @@ -23,12 +23,19 @@ export default function deBounce(fun, delay) { */ export default function deBounce(fun, delay) { var timer = 0 - return function() { + var flag = true // 是否允许执行 + return function(){ var args = arguments var context = this - if(timer) clearTimeout(timer) + if(flag) { + fun.apply(context, args) + flag = false + return + } + clearTimeout(timer) timer = setTimeout(function(){ fun.apply(context, args) - }) + flag = true + },delay) } }