-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgRotate.js
29 lines (22 loc) · 1000 Bytes
/
imgRotate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fadeInBtn = document.getElementById("fadeInBtn");
const fadeImage = document.getElementById("fadeImage");
fadeInBtn.addEventListener("click", () => {
fadeInImage(fadeImage, 3000); // 5000 milliseconds (5 seconds) duration
});
function fadeInImage(element, duration) {
let startTimestamp = null;
const rotationInterval = 360 * 1.95; // 3 circles
function updateOpacity(timestamp) {
if (!startTimestamp) startTimestamp = timestamp;
const progress = timestamp - startTimestamp;
const opacity = Math.min(progress / duration, 1);
element.style.opacity = opacity;
const rotation = (rotationInterval / duration) * progress;
element.style.transform = `rotate(${rotation}deg)`;
if (progress < duration) {
requestAnimationFrame(updateOpacity);
}
}
element.style.display = "block";
requestAnimationFrame(updateOpacity);
}