fix animation

This commit is contained in:
salam committed 2026-08-16 11:47:49 +02:00
1 parent f0bbcbc72f
commit 657f356590
10 files changed
+16046 -99

No files matched your search

+1 -2
View File
@@ -1,7 +1,6 @@
function animate(element, end, duration = 500) {
// console.log("hallo", element, end);
var element = document.getElementById(element);
const startTime = performance.now();
// Cubic easing function: slows down at the start and end
+31
View File
@@ -0,0 +1,31 @@
function animateValue(id, start, end, duration) {
// assumes integer values for start and end
var obj = document.getElementById(id);
var range = end - start;
// no timer shorter than 50ms (not really visible any way)
var minTimer = 50;
// calc step time to show all interediate values
var stepTime = Math.abs(Math.floor(duration / range));
// never go below minTimer
stepTime = Math.max(stepTime, minTimer);
// get current time and calculate desired end time
var startTime = new Date().getTime();
var endTime = startTime + duration;
var timer;
function run() {
var now = new Date().getTime();
var remaining = Math.max((endTime - now) / duration, 0);
var value = Math.round(end - remaining * range);
obj.innerHTML = value;
if (value == end) {
clearInterval(timer);
}
}
timer = setInterval(run, stepTime);
run();
}