我制作了一个自定义光标,但它在文本(p、h1、按钮、跨度)上无法正常工作。这是代码
html:
<!-- custom cursor -->
<div class="cursor"></div>
js:
const cursor = document.querySelector(".cursor");
document.addEventListener("mouseover", (e) => {
cursor.style.left = e.pageX + "px";
cursor.style.top = e.pageY + "px";
console.log(e.pageX, e.pageY); // i checked pageX and pageY values also not change when cursor moves over a text or button
})
CSS:
.cursor{
position: fixed;
width: 13px;
height: 13px;
border-radius: 50%;
background-color: #ffffff38;
transition-duration: 0.16s;
-o-transition-duration: 0.16s;
-moz-transition-duration: 0.16s;
-webkit-transition-duration: 0.16s;
transition-timing-function:ease;
-o-transition-timing-function:ease;
-moz-transition-timing-function:ease;
-webkit-transition-timing-function:ease;
transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
pointer-events: none;
mix-blend-mode: difference;
/* display: none; */
z-index: 10000;
}
它在链接上运行良好。你能告诉我如何使光标平滑移动(在所有文本和按钮上)