RetroDECK-Website/scripts/gradient.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-04-18 16:22:51 +00:00
let gradientSpinElems = document.getElementsByClassName('gradient-spin');
let gradientAngles = Array.from({ length: gradientSpinElems.length }, () => Math.floor(Math.random() * 361) + 1);
let gradientInterval;
reduceMotion();
function updateGradientAngle() {
for (let i = 0; i < gradientSpinElems.length; i++) {
2024-04-23 22:53:03 +00:00
gradientAngles[i] += Math.floor(Math.random() * 6) - 2;
if (gradientAngles[i] > 360) {
gradientAngles[i] -= 360;
} else if (gradientAngles[i] < -360) {
gradientAngles[i] += 360;
}
2024-04-19 13:39:02 +00:00
gradientSpinElems[i].style.background = `linear-gradient(${gradientAngles[i]}deg, #1a9fff, 15%, #946beb)`;
}
}
function reduceMotion() {
let reduceMotionState = document.getElementById('reduce-motion-switch').checked;
if (reduceMotionState) {
clearInterval(gradientInterval);
2024-04-19 15:01:06 +00:00
// document.getElementById('screenshotCarousel').classList.remove('ride');
} else {
2024-04-19 15:01:06 +00:00
// document.getElementById('screenshotCarousel').classList.add('ride');
gradientInterval = setInterval(function () {
updateGradientAngle();
}, 100);
}
}