Hey everyone, I'm working on a custom mouse-like feature where I want the color to change to white when hovering over links. I'm having some trouble with my code - it works fine when selecting the parent element but not the child. Can anyone help me out? I've been stuck on this for about 4 hours and could really use some assistance.
Here's the code snippet:
const cursor = document.querySelector(".cursor");
const cursor2 = document.querySelector('.cursor2');
document.addEventListener('mousemove',(e) =>{
cursor.style.left = e.pageX + 'px';
cursor.style.top = e.pageY + 'px';
cursor2.style.left = e.pageX + 'px';
cursor2.style.top = e.pageY + 'px';
} )
*{
cursor: none;
}
body{
background-color: black;
}
.cursor{
position: fixed;
width: 50px;
height: 50px;
border: 1px solid #c6c6c6;
border-radius: 50%;
left: 0;
top: 0;
pointer-events: none;
transform: translate(-50%, -50%);
transition: .12s;
}
.cursor2{
position: fixed;
width: 8px;
height: 8px;
background-color: #c6c6c6;
border-radius: 50%;
left: 0;
top: 0;
pointer-events: none;
transform: translate(-50%, -50%);
transition: .06s;
}
ul li a:hover ~ .cursor {
background-color: white;
}
<div class="nav">
<ul>
<li><a href="#">Hello</a></li>
</ul>
</div>
<div class="cursor"></div>
<div class="cursor2"></div>
I've included the code above that I've been working on, but I can't seem to figure out what's causing the issue. Any help would be greatly appreciated!