diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-13 08:38:52 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-13 08:38:52 +0800 |
| commit | 1acb1eda4c47f9bc0f04a03aa3fbad17e5864432 (patch) | |
| tree | e1c2bcf61c61de947fdb28f2b9928338b924e755 /src/js | |
| parent | c9b78209ec79b6686e7a649d635531e06d49631f (diff) | |
additional features like auto switch per min
Diffstat (limited to 'src/js')
| -rw-r--r-- | src/js/rbg.js | 31 |
1 files changed, 24 insertions, 7 deletions
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); |
