实现一个鼠标跟随

<style>
  #pionter {
    width: 20px;
    height: 20px;
    background: pink;
    border-radius: 20px;
    position: absolute;
  }
</style>
<div id="pionter"></div>
<script>
  window.onload = function () {
    var pionter = document.querySelector('#pionter');
    window.onmousemove = function (e) {
      setTimeout(()=>{
        pionter['style']['left'] = e.clientX-10 + 'px';
        pionter['style']['top'] = e.clientY-10 + 'px';
      },30)
    };
  }; 
</script>
 

posted @ 2020-07-23 16:39  五环  阅读(172)  评论(0编辑  收藏  举报