Block color now in class instead of modifying inline style

This commit is contained in:
NetMan 2024-01-09 20:18:10 +01:00
parent 7c9c46779f
commit 265efa765a
2 changed files with 10 additions and 2 deletions

View File

@ -14,9 +14,13 @@ function createGrid(size) {
let blocks = document.querySelectorAll(".block"); let blocks = document.querySelectorAll(".block");
blocks.forEach(block => { blocks.forEach(block => {
block.addEventListener("mouseover", (event) => {event.target.style.backgroundColor = "#000"}); block.addEventListener("mouseover", (event) => {
event.target.classList.add("colored")
});
block.addEventListener("mouseout", (event) => { block.addEventListener("mouseout", (event) => {
setTimeout(() => event.target.style.backgroundColor = "#fff", 1 * 1000); setTimeout(() => {
event.target.classList.remove("colored");
}, 1 * 1000);
}); });
}) })
} }

View File

@ -12,4 +12,8 @@
/* padding: 10px; */ /* padding: 10px; */
flex: 1; flex: 1;
aspect-ratio: 1 / 1; aspect-ratio: 1 / 1;
}
.colored {
background-color: #000;
} }