我有一个代码,用于在鼠标静止时使导航栏消失,当鼠标移动时,它应该淡入。代码有效,但当鼠标静止时,导航栏会褪色然后会在几秒钟后消失,并且会定期继续淡出。有问题的网站是here。 我的代码低于
$("#header").hide();
$("html").mousemove(function( event ) {
$("#header").fadeIn(1500);
myStopFunction();
myFunction();
});
function myFunction() {
myVar = setTimeout(function(){
$("#header").fadeOut(1500);
}, 2000);
}
function myStopFunction() {
if(typeof myVar != 'undefined'){
clearTimeout(myVar);
}
}
答案 0 :(得分:1)
试试这个(模式)
$(function () {
var _toggle = function () {
$(document).one("mousemove.t", function (e) {
e.target = $("#header");
$(e.target).toggle(1500).delay(2000).toggle(1500, function () {
_toggle()
})
})
};
$.when(_toggle())
})