我想要一个视频播放器全屏,并且我想让控件在mousemove
上显示。由于没有mousestop
我刚启动了一个计时器,如果它完成,它将隐藏工具。jQuery mousemove自己触发
问题 - 由于我怀疑回调的性质,效果不断在显示和隐藏之间来回切换。该类mouseMoving
在CSS中添加display: block !important
,当它被删除,theControls
返回到它的原始的CSS这是display: none !important
$('#theDiv').mousemove(
function()
{
//When the mouse is moving, add the class which adds display: block !important
$('#theControls').addClass('mouseMoving');
// Clear the timer each time the mouse moves, so that if the mouse doesnt move for a full 2 seconds,
// hide the controls by removing the afforementioned class.
clearTimeout(timer);
var timer = setTimeout(
function()
{
$('#theControls').removeClass('mouseMoving');
},
2000);
}
);
事实上,如果你走在全屏幕和移动鼠标,该控件将出现,然后隐藏,然后开发工具将显示类mouseMoving
正在不断被追加和删除,即使我不再移动鼠标,。这将无限期地继续下去,或者直到鼠标再次移动,然后循环重复。
你为什么叫'clearTimer'上'timer'定义之前呢?你不应该在闭包之外定义'timer',所以你可以这样做吗? – ahitt6345
而且,你的意思是'clearTimer'或'clearTimeout'?因为除非你定义了'clearTimer',否则不存在。 – ahitt6345
@ ahitt6345我的意思是'clearTimeout'抱歉,把它改了。 –