Center node in the viewport

This commit is contained in:
barsdeveloper
2022-12-27 17:55:54 +01:00
parent a1ae7799a1
commit 0def4f7e48
7 changed files with 282 additions and 101 deletions

View File

@@ -324,4 +324,22 @@ export default class Utility {
event.clipboardData.setData("text", value)
element.dispatchEvent(event)
}
static animate(from, to, intervalSeconds, callback, timingFunction = x => {
const v = x ** 3.5
return v / (v + ((1 - x) ** 3.5))
}) {
const startTimestamp = performance.now()
const doAnimation = currentTimestamp => {
let delta = (currentTimestamp - startTimestamp) / intervalSeconds
if (Utility.approximatelyEqual(delta, 1) || delta > 1) {
delta = 1
} else {
requestAnimationFrame(doAnimation)
}
const currentValue = from + (to - from) * timingFunction(delta)
callback(currentValue)
}
requestAnimationFrame(doAnimation)
}
}