鼠标跟随主要根据X,Y轴来计算
主要代码函数是
span[0].style.left = event.clientX + “px”; 计算X轴
span[0].style.top = event.clientY + “px”; 计算Y轴
<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title></title><style type="text/css">*{margin: 0;padding: 0;}span {position: absolute;width: 40px;height: 40px;background: red;border-radius: 50%;}</style></head><body><span></span><script type="text/javascript">var span = document.getElementsByTagName("span");document.onmousemove = function() {
// clientX返回当事件被触发时鼠标指针向对于浏览器页面(或客户区)的水平坐标 span[0].style.left = event.clientX + "px";span[0].style.top = event.clientY + "px";}</script></body></html>