[wip] Add reducing side margin effect on Photos when scrolling

This commit is contained in:
2021-10-12 22:12:24 +02:00
parent 56c523679b
commit db8f984739
3 changed files with 77 additions and 8 deletions

View File

@@ -1,3 +1,29 @@
/**
* Throttle function
*/
export const throttle = (func: Function, timeout: number) => {
let ready: boolean = true
return (...args: any) => {
if (!ready) return
ready = false
func(...args)
setTimeout(() => ready = true, timeout)
}
}
/**
* Debounce function
*/
export const debounce = (func: Function, timeout: number) => {
let timer: NodeJS.Timeout
return (...args: any) => {
clearTimeout(timer)
timer = setTimeout(() => func(...args), timeout)
}
}
/**
* Linear Interpolation
*/
@@ -6,6 +32,15 @@ export const lerp = (start: number, end: number, amt: number): number => {
}
/**
* Clamp a number
*/
export const clamp = (num: number, a: number, b: number) => {
return Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b))
}
/**
* Return a random element from an array
*/