From 627c3e0a6920131d75eafa4646db373ccc936546 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 26 十月 2023 13:52:07 +0800
Subject: [PATCH] 小程序diamante
---
minipro_standard/uni_modules/uview-ui/libs/function/throttle.js | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/minipro_standard/uni_modules/uview-ui/libs/function/throttle.js b/minipro_standard/uni_modules/uview-ui/libs/function/throttle.js
new file mode 100644
index 0000000..2f33611
--- /dev/null
+++ b/minipro_standard/uni_modules/uview-ui/libs/function/throttle.js
@@ -0,0 +1,30 @@
+let timer; let
+ flag
+/**
+ * 鑺傛祦鍘熺悊锛氬湪涓�瀹氭椂闂村唴锛屽彧鑳借Е鍙戜竴娆�
+ *
+ * @param {Function} func 瑕佹墽琛岀殑鍥炶皟鍑芥暟
+ * @param {Number} wait 寤舵椂鐨勬椂闂�
+ * @param {Boolean} immediate 鏄惁绔嬪嵆鎵ц
+ * @return null
+ */
+function throttle(func, wait = 500, immediate = true) {
+ if (immediate) {
+ if (!flag) {
+ flag = true
+ // 濡傛灉鏄珛鍗虫墽琛岋紝鍒欏湪wait姣鍐呭紑濮嬫椂鎵ц
+ typeof func === 'function' && func()
+ timer = setTimeout(() => {
+ flag = false
+ }, wait)
+ }
+ } else if (!flag) {
+ flag = true
+ // 濡傛灉鏄潪绔嬪嵆鎵ц锛屽垯鍦╳ait姣鍐呯殑缁撴潫澶勬墽琛�
+ timer = setTimeout(() => {
+ flag = false
+ typeof func === 'function' && func()
+ }, wait)
+ }
+}
+export default throttle
--
Gitblit v1.9.3