Update 'frontend.js'
This commit is contained in:
parent
44b926e6f3
commit
58df23243e
1 changed files with 23 additions and 4 deletions
27
frontend.js
27
frontend.js
|
@ -328,12 +328,31 @@ function fadeIn(el, ms) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function spin(el, ms){
|
function spin(elementID, duration) {
|
||||||
elem = getElementById(el);
|
const element = document.getElementById(elementID);
|
||||||
for (i = 0; i < (ms / 361); i++) {
|
if (!element) {
|
||||||
elem.style.transform = 'rotate(' + i + 'deg)';
|
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
|
//Eval alternative
|
||||||
//Example: exec("alert('Hello, world!')")
|
//Example: exec("alert('Hello, world!')")
|
||||||
|
|
Loading…
Reference in a new issue