div
按住鼠标左键时如何使红色像这样工作而不是什么时候mousemove
const cursor = document.querySelector('.cursor');
document.addEventListener( 'mousemove', e => {
cursor.style.left = e.clientX + 'px';
cursor.style.top = e.clientY + 'px';
});
.cursor {
width: 30px;
height: 30px;
transform: translate(-50%,-50%);
position: absolute;
background-color: red;
}
<div class="cursor"></div>
作为一个粗略的近似: