我正在尝试创建两条线(一条垂直的 100 VH 和 1 px 的宽度,一条水平的 100vw 和 1 px 的高度),它们始终跟随鼠标光标并相互感兴趣。我的代码有两个问题:1)我不知道我必须在垂直线上分配什么高度值(水平线很容易,我将它设置为 200 vw 和 body overflow-x hidden 所以没关系) 和 2) 当我向下滚动时,直到我不移动鼠标,水平线保持在同一位置,只有在我更改鼠标位置后它才会跟随光标。这是我的代码:
const cursor = document.querySelector('.cursor');
document.addEventListener('mousemove', e => {
cursor.setAttribute("style", "top: " + (e.pageY) + "px; left: " + (e.pageX) + "px;")
})
body {
overflow-x: hidden;
height: 5000px;
}
.cursor {
position: absolute;
}
.cursor-lines {
position: relative;
}
.vt {
position: absolute;
height: 200vh;
top: -100vh;
width: 1px;
background: black;
}
.hl {
position: absolute;
left: -100vw;
height: 1px;
width: 200vw;
background: black;
}
<div class="cursor">
<div class="cursor-lines">
<div class="vt"></div>
<div class="hl"></div>
</div>
</div>