[BUG] UI shifting in mobile browser #2488

This commit is contained in:
Cohee
2024-07-07 20:12:04 +03:00
parent 6ff406f6ea
commit ed0e522c6d
2 changed files with 28 additions and 1 deletions

View File

@ -301,6 +301,32 @@ export function throttle(func, limit = 300) {
};
}
/**
* Creates a debounced throttle function that only invokes func at most once per every limit milliseconds.
* @param {function} func The function to throttle.
* @param {number} [limit=300] The limit in milliseconds.
* @returns {function} The throttled function.
*/
export function debouncedThrottle(func, limit = 300) {
let last, deferTimer;
let db = debounce(func);
return function() {
let now = +new Date, args = arguments;
if(!last || (last && now < last + limit)) {
clearTimeout(deferTimer);
db.apply(this, args);
deferTimer = setTimeout(function() {
last = now;
func.apply(this, args);
}, limit);
} else {
last = now;
func.apply(this, args);
}
};
}
/**
* Checks if an element is in the viewport.
* @param {Element} el The element to check.