【问题标题】:javascript mousemove event in fullscreen全屏中的javascript mousemove事件
【发布时间】:2013-10-11 05:22:11
【问题描述】:

由于某种原因,在 PC 上的 chrome 中(在 mac 上不会发生),当您进入全屏模式时,会弹出一个内置的小 chrome div,说您现在处于全屏模式,当该 div 消失时,它会触发 @987654322 @ 事件。知道为什么吗?

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

当鼠标实际上没有移动时,它基本上会导致我的空闲鼠标功能触发。这似乎只发生在 chrome 中。 PC 上的 Firefox 不这样做,mac 上的 chrome 不这样做。我正在使用google chrome 30.0.1599.69 m

解决方案

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

【问题讨论】:

  • 很奇怪。我也在30.0.1599.69 m 上,即使我没有移动鼠标,我也会每秒收到mousemove 事件。 jsfiddle.net/vnJZe
  • 嗯,我的只有在鼠标移动时才会触发

标签: javascript jquery google-chrome fullscreen


【解决方案1】:

你可以使用这样的函数:

(注意:我使用全局变量window,记得用你的全局变量更改它!)

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

为了避免这个事件,我猜想事件触发当鼠标改变这个窗口然后返回到Chrome的DOM。

【讨论】:

  • 感谢您的想法。虽然我无法使用event.x,但我找到了event.clientX,修改了我的函数并确认它适用于所有浏览器
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-29
  • 1970-01-01
  • 2023-03-09
相关资源
最近更新 更多