JSFIDDLE DEMO
延時定時器復位隨時隨地用戶觸發上#gallery鼠標移動或按鍵事件。您也可以在該處添加懸停事件,以確保在#gallery上懸停時菜單永遠不會隱藏。
var interval = 1;
function delayCheck()
{
if(interval == 5)
{
$('#menuwrap').animate({top: '-50px'}, 100);
interval = 1;
}
interval = interval+1; console.log(interval);
}
$('#gallery').bind('mousemove keypress', function() {
$('#menuwrap').animate({top: '0'}, 100);
interval = 1;
// reset the delay timer
clearInterval(_delay); console.log('reset timer');
_delay = setInterval(delayCheck, 500);
});
// starts delay timer when page loads
_delay = setInterval(delayCheck, 500);
答案PART 2周
JSFIDDLE DEMO #2
只有不活動檢查一次#gallery事件鼠標移動或按鍵已被觸發。一旦用戶移出#gallery框,它將終止delayCheck()並將#menuwrap設置回頂部:-50px。
var interval = 1;
_delay = 0;
function delayCheck()
{
if(interval == 5)
{
$('#menuwrap').animate({top: '-50px'}, 100);
interval = 1;
clearInterval(_delay);
}
interval = interval+1;
console.log(interval);
}
// turn delayCheck() ON, when mousing to #gallery
$('#gallery').bind('mousemove keypress', function()
{
console.log("mousemove keypress");
$('#menuwrap').animate({top: '0'}, 100);
interval = 1;
// reset delayCheck
clearInterval(_delay);
_delay = setInterval(delayCheck, 500);
});
// turn delayCheck() OFF, when mousing out of #gallery
$('#gallery').mouseout(function(){
console.log("mouseout");
$('#menuwrap').animate({top: '-50px'}, 100);
interval = 1;
clearInterval(_delay);
});
非常感謝!不知道如何使延遲檢查僅在用戶通過#gallery閒置時觸發...您是否和我一起?我不希望#menuwrap在用戶懸停#menuwrap時纔會出現-50px,僅當用戶懸停時#gallery – 2012-04-04 20:32:56
http://jsfiddle.net/959wF/4/用懸停進行更新但仍然在#gallery外部動畫 – 2012-04-04 20:39:03
它。讓我稍微修改一下。 – 2012-04-04 20:50:02