Skip to content

Commit

Permalink
Simplify and Optimise backgroundRandomiser.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRowey committed May 22, 2024
1 parent 8c3ca5f commit 80d60f0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/backgroundRandom.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
function setBackground(x){
function setBackground({matches}){
const htmlElement = document.documentElement;

if (x.matches) {
if (matches) {
htmlElement.style.backgroundColor = "var(--Background)";
htmlElement.style.backgroundImage = "";
} else {
const imgs = [
'../assets/images/backgrounds/1.jpg',
Expand All @@ -14,6 +15,7 @@ function setBackground(x){
];
const randomImg = imgs[Math.floor(Math.random() * imgs.length)];
htmlElement.style.backgroundImage = `url(${randomImg})`;
htmlElement.style.backgroundColor = "";
}
}

Expand Down

0 comments on commit 80d60f0

Please sign in to comment.