search

Home  >  Q&A  >  body text

javascript - How to get the mouse position when the mouse is not moving (without mousemove)

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~

仅有的幸福仅有的幸福2705 days ago1079

reply all(6)I'll reply

  • PHP中文网

    PHP中文网2017-07-05 10:57:20

    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

    reply
    0
  • 学习ing

    学习ing2017-07-05 10:57:20

    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 };

    }

    reply
    0
  • 天蓬老师

    天蓬老师2017-07-05 10:57:20

    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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-07-05 10:57:20

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

    reply
    0
  • 巴扎黑

    巴扎黑2017-07-05 10:57:20

    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 triggered mousemove

    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: mousemove has been triggered and observable data has been generated. Before that, it was all undefined.

    reply
    0
  • 高洛峰

    高洛峰2017-07-05 10:57:20

    Continue to pay attention and wait for the master

    reply
    0
  • Cancelreply