[wip] Add reducing side margin effect on Photos when scrolling
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user