简体   繁体   中英

Webkit firing mousemove event unexpectedly (mouse not moving)

I have a slideshow playing that scrolls a div to reveal the next photo in the slideshow. I also have a function set up that hides the photo description when the mouse is inactive, but shows the description when the mouse moves.

In Firefox, there is no problem, the div scrolls to new photos and no mousemove event is fired. However, in Webkit with the mouse on the window, but inactive, two-three mousemove events are fired every time the div scrolls to a new photo.

Here's the website for you to have a look. Navigate to the portfolio page in a webkit browser (with a console open I suppose) and that footer should stay hidden while the photos cycle through. http://96.0.13.132/

Yes, webkit browsers do that, and i think every browser should. Because the cursor IS in a different position after the scrolling, and that could avoid me a lot of problems as a developer.

Anyway, if you want to avoid its consequences in your script, just log the latest clientX and clientY position and check if those have changed since the last "mousemove"; something like this:

window.addEventListener("mousemove",function(e){
    if(window.lastX !== e.clientX || window.lastY !== e.clientY){
        // Code when the (physical) mouse actually moves
    }   
    window.lastX = e.clientX
    window.lastY = e.clientY
})

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