Add throttle util

This commit is contained in:
SillyLossy
2023-06-08 16:29:45 +03:00
parent 87125cb3b5
commit fa7e7cfb5b

View File

@ -93,6 +93,17 @@ export function debounce(func, timeout = 300) {
};
}
export function throttle(func, limit = 300) {
let lastCall;
return (...args) => {
const now = Date.now();
if (!lastCall || (now - lastCall) >= limit) {
lastCall = now;
func.apply(this, args);
}
};
}
export function isElementInViewport(el) {
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];