【发布时间】:2021-12-30 20:49:49
【问题描述】:
大家好,我正在创建一个自定义的类似鼠标的东西,我希望它在悬停链接时颜色为白色 IDK what's wrong with my code, it's not working properly when select parent element it works fine but when I use child element it's not working help me out, I got stuck with this code for like 4 hours I need help
这是我的代码
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>
我只是粘贴了我编码的任何代码,我不知道问题是什么。
【问题讨论】:
标签: html css css-selectors