From 7a4c2802ba039e9466c7e9cf9a149baa99daa0a8 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Sat, 6 May 2023 17:42:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20layui=20=E9=98=B2=E6=8A=96?= =?UTF-8?q?=E5=92=8C=E8=8A=82=E6=B5=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layui.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/layui.js b/src/layui.js index 9b676cc4..c32a4147 100644 --- a/src/layui.js +++ b/src/layui.js @@ -787,9 +787,38 @@ var that = this; return that.event.call(that, modName, events, EV_REMOVE); }; - + + // 防抖 + Layui.prototype.debounce = function (func, wait) { + var timeout; + return function () { + var context = this; + var args = arguments; + clearTimeout(timeout); + timeout = setTimeout(function () { + func.apply(context, args); + }, wait); + } + }; + + // 节流 + Layui.prototype.throttle = function (func, wait) { + var cooldown = false; + return function () { + var context = this; + var args = arguments; + if (!cooldown) { + func.apply(context, args); + cooldown = true; + setTimeout(function () { + cooldown = false; + }, wait); + } + } + }; + // exports layui win.layui = new Layui(); - + }(window); // gulp build: layui-footer