From 58df23243ed7c9cd49a97614f5a7e1e4a52f191f Mon Sep 17 00:00:00 2001 From: Maxwell Drake Date: Sun, 7 Apr 2024 21:37:39 +0000 Subject: [PATCH] Update 'frontend.js' --- frontend.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/frontend.js b/frontend.js index faa9849..4e230d2 100644 --- a/frontend.js +++ b/frontend.js @@ -328,13 +328,32 @@ function fadeIn(el, ms) { } } -function spin(el, ms){ - elem = getElementById(el); - for (i = 0; i < (ms / 361); i++) { - elem.style.transform = 'rotate(' + i + 'deg)'; +function spin(elementID, duration) { + const element = document.getElementById(elementID); + if (!element) { + console.error(`Element with ID '${elementID}' not found.`); + return; } + + let start; + const animate = (timestamp) => { + if (!start) start = timestamp; + const elapsed = timestamp - start; + const rotation = (elapsed / duration) * 360; + element.style.transform = `rotate(${rotation}deg)`; + + if (elapsed < duration) { + requestAnimationFrame(animate); + } else { + start = null; + element.style.transform = 'none'; // Reset transform after animation completes + } + }; + + requestAnimationFrame(animate); } + //Eval alternative //Example: exec("alert('Hello, world!')") function exec(jsCode) {