Interactive Background Not Working (HTML, CSS, Javascript)
-
I’m coding an interactive grid effect background based on this link: https://codepen.io/Hyperplexed/pen/RwzGKwy
The plane rotation skews all the elements on my website so I made changes to the code provided.
I added this HTML to an HTML block in Elementor:
<div id="container">
<div class="tile"></div>
</div>
</div>I added this CSS to Additional CSS (Appearance > Customize > Additional CSS):
:root {
--red-rgb: 248 113 113;
--blue-rgb: 56 189 248;
--green-rgb: 74 222 128;
--yellow-rgb: 253 224 71;
--background-rgb: transparent;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#container {
width: 140rem;
aspect-ratio: 1;
display: grid;
grid-template-rows: repeat(40, 1fr);
grid-template-columns: repeat(40, 1fr);
position: absolute;
transform: scale(1.25);
}
#container:after,
#container:before {
content: "";
position: absolute;
inset: 0px;
pointer-events: none;
}
#container:before {
z-index: 2;
background-size: 5%;
background-repeat: repeat;
opacity: 0.25;
}
#container:after {
z-index: 3;
background: radial-gradient(circle, transparent 25%, rgb(var(--background-rgb)) 80%);
}
.tile {
border: 1px solid rgb(255 255 255 / 25%);
transition: background-color 1500ms;
}
.tile:hover {
transition-duration: 0ms;
}
.tile:nth-child(4n):hover {
background-color: rgb(var(--red-rgb));
}
.tile:nth-child(4n + 1):hover {
background-color: rgb(var(--blue-rgb));
}
.tile:nth-child(4n + 2):hover {
background-color: rgb(var(--green-rgb));
}
.tile:nth-child(4n + 3):hover {
background-color: rgb(var(--yellow-rgb));
}
.tile:nth-child(7n):hover {
background-color: rgb(var(--blue-rgb));
}
.tile:nth-child(7n + 3):hover {
background-color: rgb(var(--green-rgb));
}
.tile:nth-child(7n + 5):hover {
background-color: rgb(var(--yellow-rgb));
}
.tile:nth-child(7n + 6):hover {
background-color: rgb(var(--red-rgb));
}
.tile:nth-child(11n + 1):hover {
background-color: rgb(var(--red-rgb));
}
.tile:nth-child(11n + 4):hover {
background-color: rgb(var(--blue-rgb));
}
.tile:nth-child(11n + 7):hover {
background-color: rgb(var(--green-rgb));
}
.tile:nth-child(11n + 10):hover {
background-color: rgb(var(--yellow-rgb));
}I installed WPCode and created a new snippet (it is Active, code type: JavaScript Snippet, Insert Method: Auto Insert, Device Type: Any Device):
const container = document.querySelector("#container"),
tile = document.querySelector(".tile");
for(let i = 0; i < 1599; i++) {
container.appendChild(tile.cloneNode());
}With this code setup above, I can get the page to blink one color but it’s not functioning as expected. How can I fix this?
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.