Implement Interactive Globe on Homepage

This commit is contained in:
2021-10-03 13:56:11 +02:00
parent 2634e0473a
commit f6da3c4b55
8 changed files with 355 additions and 121 deletions

View File

@@ -3,4 +3,31 @@
*/
export const lerp = (start: number, end: number, amt: number): number => {
return (1 - amt) * start + amt * end
}
/**
* Return a random element from an array
*/
export const getRandomElement = (array: any[]): any => {
return ~~(array.length * Math.random())
}
/**
* Get a DOM element's position
*/
export const getPosition = (node, scope?: HTMLElement) => {
const root = scope || document
let offsetTop = node.offsetTop
let offsetLeft = node.offsetLeft
while (node && node.offsetParent && node.offsetParent != document && node !== root && root !== node.offsetParent) {
offsetTop += node.offsetParent.offsetTop
offsetLeft += node.offsetParent.offsetLeft
node = node.offsetParent
}
return {
top: offsetTop,
left: offsetLeft
}
}