简体   繁体   中英

Mousemove event added in mousedown event keeps firing while the mouse is not moving

I am working at a simple sequence of mouse event listeners in the form of "mousedown" -> "mousemove" -> "mouseup". What I am trying to do is add two event listeners for mousemove and mouseup when the mousedown event fires.

My code looks like this:

 document.addEventListener("mousedown",stagesContainerGrabMouseDownHandler) function stagesContainerGrabMouseDownHandler(ev){ document.addEventListener("mousemove",stagesContainerGrabMouseMoveHandler); document.addEventListener("mouseup",stagesContainerGrabMouseUpHandler) } function stagesContainerGrabMouseMoveHandler(ev){ console.log(12) } function stagesContainerGrabMouseUpHandler(ev){ document.removeEventListener("mousemove",stagesContainerGrabMouseMoveHandler); document.removeEventListener("mouseup",stagesContainerGrabMouseUpHandler); }

The problem is that when I keep the mouse pressed, the mousemove event keeps firing even if my mouse stays still. I am using Chrome.

It appears that the issue must be coming from somewhere else — perhaps other code or the mouse you're using.

I tested the code you included in a DevTools Console (both in Edge and Chrome) and the event doesn't fire when I keep my mouse pressed down and still.

So I have found the culprit. I didn't even think to look there. I am running a script in the background with AutoHotKey and for some reason it seems that it interacts with my page. Turning it off solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM