Javascript - Track mouse position

后端 未结 11 1528
谎友^
谎友^ 2020-11-22 03:13

I am hoping to track the position of the mouse cursor, periodically every t mseconds. So essentially, when a page loads - this tracker should start and for (say) every 100 m

11条回答
  •  孤城傲影
    2020-11-22 03:54

    What I think that he only wants to know the X/Y positions of cursor than why answer is that complicated.

    // Getting 'Info' div in js hands
    var info = document.getElementById('info');
    
    // Creating function that will tell the position of cursor
    // PageX and PageY will getting position values and show them in P
    function tellPos(p){
      info.innerHTML = 'Position X : ' + p.pageX + '
    Position Y : ' + p.pageY; } addEventListener('mousemove', tellPos, false);
    * {
      padding: 0:
      margin: 0;
      /*transition: 0.2s all ease;*/
      }
    #info {
      position: absolute;
      top: 10px;
      right: 10px;
      background-color: black;
      color: white;
      padding: 25px 50px;
    }
    
    
      
      
        

提交回复
热议问题