简体   繁体   English

Webkit 意外触发 mousemove 事件(鼠标不动)

[英]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.我有一个幻灯片播放,滚动 div 以显示幻灯片中的下一张照片。 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.在 Firefox 中,没有问题,div 滚动到新照片并且没有触发mousemove事件。 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.但是,在 Webkit 中,鼠标在窗口上,但处于非活动状态,每次 div 滚动到新照片时都会触发两到三个mousemove事件。

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.在 webkit 浏览器中导航到投资组合页面(我想打开一个控制台),当照片循环时,页脚应该保持隐藏。 http://96.0.13.132/ http://96.0.13.132/

Yes, webkit browsers do that, and i think every browser should.是的,webkit 浏览器会这样做,我认为每个浏览器都应该这样做。 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";无论如何,如果你想避免它在你的脚本中的后果,只需记录最新的 clientX 和 clientY 位置并检查自上次“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
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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