简易鼠标移动

来源:互联网 发布:阿里云cdn加速配置 编辑:程序博客网 时间:2024/06/06 00:48
document.addEventListener("mousemove", function (e) {
box.style.left = e.pageX-box.offsetWidth/2+"px";
box.style.top = e.pageY-box.offsetHeight/2+"px";
})
我想将光标原点放在盒子的中间
得到的e.pageX减去盒子宽度的一半-box.offsetWidth/2(y同理)
原创粉丝点击