javascript - How to get the mouse position when the mouse is not moving (without mousemove)
仅有的幸福
仅有的幸福 2017-07-05 10:55:20
0
6
1023

How to get the mouse position when the mouse is not moving (no mousemove)
js jq will do anything


What everyone said makes sense, and I am very happy to study this problem with you~ Waiting for the master~ Or maybe there is really no way at this stage~

仅有的幸福
仅有的幸福

reply all (6)
Ty80

If you are not moving after mousemove, just use a variable to save the coordinates of the last move, and read the value of this variable in the future.
If you want to get the coordinates of the mouse when the page is first loaded, I just tried a few events and it doesn’t seem to work. Wait for the master to help you

    学习ing

    It seems that if there is no mouse event, the position cannot be obtained. Is onclick event OK? If it doesn't work, just pretend I didn't say it.

    document.onclick = getMousePos;

    function getMousePos(event) {

    var e = event || window.event; var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; var scrollY = document.documentElement.scrollTop || document.body.scrollTop; var x = e.pageX || e.clientX + scrollX; var y = e.pageY || e.clientY + scrollY; return { 'x': x, 'y': y };

    }

      Peter_Zhu

      Acquiring the mouse and keyboard belongs to the event class. The event is that event. If you do not generate an event, you cannot obtain the mouse position

        我想大声告诉你

        Sit back and wait for the master. After trying F5, I still can’t get the coordinates

          巴扎黑

          If there is no trigger event, there is almost no way to obtain the coordinates.


          A not-so-nice note:

          Let me assume one thing first:

          The user has moved the mouse before, which means it has triggeredmousemove

          Save the last triggered position when it has been triggered.

          It’s not too far away compared to when your mouse doesn’t move at all.

          If you need more accuracy, you may need to analyze the path.

          But they are all based on one assumption:mousemovehas been triggered and observable data has been generated. Before that, it was all undefined.

            小葫芦

            Continue to pay attention and wait for the master

              Latest Downloads
              More>
              Web Effects
              Website Source Code
              Website Materials
              Front End Template
              About us Disclaimer Sitemap
              php.cn:Public welfare online PHP training,Help PHP learners grow quickly!