mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 14:41:20 -08:00
update docs
This commit is contained in:
1 parent
84c84e4cda
commit
e3e42eb399
115 files changed
+279
-598
No files matched your search
@@ -2,45 +2,31 @@ export function sleep(ms = 0) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export function debounce(func, wait, context) {
|
||||
export function debounce(func, duration) {
|
||||
let timeout;
|
||||
function fn(...args) {
|
||||
const later = function later() {
|
||||
|
||||
return function (...args) {
|
||||
const effect = () => {
|
||||
timeout = null;
|
||||
func.apply(context, args);
|
||||
return func.apply(this, args);
|
||||
};
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
}
|
||||
|
||||
fn.clearTimeout = function ct() {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(effect, duration);
|
||||
};
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
export function throttle(callback, delay) {
|
||||
let isThrottled = false;
|
||||
let args;
|
||||
let context;
|
||||
function fn(...args2) {
|
||||
if (isThrottled) {
|
||||
args = args2;
|
||||
context = this;
|
||||
return;
|
||||
export function throttle(func, duration) {
|
||||
let shouldWait = false;
|
||||
|
||||
return function (...args) {
|
||||
if (!shouldWait) {
|
||||
func.apply(this, args);
|
||||
shouldWait = true;
|
||||
|
||||
setTimeout(function () {
|
||||
shouldWait = false;
|
||||
}, duration);
|
||||
}
|
||||
|
||||
isThrottled = true;
|
||||
callback.apply(this, args2);
|
||||
setTimeout(() => {
|
||||
isThrottled = false;
|
||||
if (args) {
|
||||
fn.apply(context, args);
|
||||
args = null;
|
||||
context = null;
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
return fn;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user