简体   繁体   English

全屏的javascript mousemove事件

[英]javascript mousemove event in fullscreen

For some reason, in chrome on PC (not happening on mac), when you enter full screen, the little built in chrome div pops up saying you are now in fullscreen mode and when that div dissapears, it fires a mousemove event. 出于某种原因,在PC上的chrome中(在Mac上没有),当您进入全屏模式时,会弹出一个内置的chrome div小提示,表示您现在处于全屏模式,并且当该div消失时,它会触发mousemove事件。 Any idea why? 知道为什么吗?

var idleTimer;
$videoContainer.mousemove(function()
{
    if (!$jsplayer.prop('paused'))
    {
        if (idleTimer)
        {
            clearTimeout(idleTimer);
            $videoControls.stop(true,true).animate({opacity:1}, animationDuration);
        }
        idleTimer = setTimeout(function(){
            $videoControls.stop(true,true).animate({opacity:0}, animationDuration);
        },3000);
    }
});

It is basically causing my idle mouse function to fire when the mouse isn't actually moving. 基本上,这是导致我的闲置鼠标功能在鼠标实际上没有移动时触发。 This seems to only be happening in chrome. 这似乎仅在Chrome中发生。 Firefox on the PC doesn't do it, chrome on the mac doesn't do it. PC上的Firefox不支持,Mac上的chrome不支持。 I am using google chrome 30.0.1599.69 m 我正在使用google chrome 30.0.1599.69 m

SOLUTION

var idleTimer;
var prevX;
$videoContainer.mousemove(function(e)
{
    if (!$jsplayer.prop('paused'))
    {
        if (idleTimer)
        {
            clearTimeout(idleTimer);
            if (prevX != e.clientX) $videoControls.stop(true,true).animate({opacity:1});
        }
        prevX = e.clientX;
        idleTimer = setTimeout(function(){
            if (!$jsplayer.prop('paused')) $videoControls.stop(true,true).animate({opacity:0}, animationDuration);
        },3000);
    }
});

You can use a function like this: 您可以使用如下功能:

(note: I use a global var window , remember change it with your global var!) (注意:我使用的是全局变量窗口 ,请记住使用全局变量来更改它!)

window.prev_x = null;
function mousemover(e) {
    if ((window.prev_x != null) && (window.prev_x != e.x)) {
        alert(e.x + ' - '+ window.prev_x);
    }
    window.prev_x = e.x;
};
document.addEventListener('mousemove', mousemover, false);

To avoid this event, i guess that event fire when the mouse change this window and then return to DOM of Chrome. 为了避免发生此事件,我认为当鼠标更改此窗口然后返回到Chrome的DOM时会触发事件

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

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