我有一个仅在mousemove上显示的菜单。我希望它在鼠标悬停在菜单区域时保持显示状态。
我现在有以下代码,不确定如何更改它以满足我的需求。
var timer;
$("html").on('mousemove', function() {
$('nav').addClass('show');
try {
clearTimeout(timer);
} catch (e) {}
timer = setTimeout(function() {
$('nav').removeClass('show');
}, 2000);
});
谢谢
答案 0 :(得分:0)
可能不是最好的方法,但是使用以下if语句可获得结果:
var timer;
$("html").on('mousemove', function() {
$('nav').addClass('show');
try {
clearTimeout(timer);
} catch (e) {}
if ($('nav:hover').length != 0) {
}else
timer = setTimeout(function() {
$('nav').removeClass('show');
}, 2000);
});