From 1acb1eda4c47f9bc0f04a03aa3fbad17e5864432 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 13 Oct 2023 08:38:52 +0800 Subject: additional features like auto switch per min --- src/js/rbg.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/js') diff --git a/src/js/rbg.js b/src/js/rbg.js index 0b1cec5f..40f0dadd 100644 --- a/src/js/rbg.js +++ b/src/js/rbg.js @@ -1,3 +1,5 @@ +document.body.style.transition = "background 1s ease-in-out"; + function getRandomColor() { const letters = "0123456789ABCDEF"; let color = "#"; @@ -8,17 +10,32 @@ function getRandomColor() { } function setRandomGradient() { - const rand3 = Math.floor(Math.random()); + const rand3 = Math.floor(Math.random() * 3) + 1; if (rand3 === 1) { - document.body.style.background = `linear-gradient(${Math.floor(Math.random() * 180)}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()})`; + document.body.style.background = `linear-gradient(${Math.floor( + Math.random() * 180 + )}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()})`; } else if (rand3 === 2) { - document.body.style.background = `linear-gradient(${Math.floor(Math.random() * 180)}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}), -linear-gradient(${Math.floor(Math.random() * 180)}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()})`; + document.body.style.background = `linear-gradient(${Math.floor( + Math.random() * 180 + )}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}), +linear-gradient(${Math.floor( + Math.random() * 180 + )}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()})`; } else { - document.body.style.background = `linear-gradient(${Math.floor(Math.random() * 180)}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}), -linear-gradient(${Math.floor(Math.random() * 180)}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}), -linear-gradient(${Math.floor(Math.random() * 180)}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()})`; + document.body.style.background = `linear-gradient(${Math.floor( + Math.random() * 180 + )}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}), +linear-gradient(${Math.floor( + Math.random() * 180 + )}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}), +linear-gradient(${Math.floor( + Math.random() * 180 + )}deg, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()}, ${getRandomColor()})`; } } setRandomGradient(); + +// Execute setRandomGradient() every 1 minute +setInterval(setRandomGradient, 60000); -- cgit v1.2.3