2015-07-19 45 views
0

你好傢伙讀這個article我創建簡單的屏幕保護程序,但我有一個問題,當我讓我的鼠標停止我需要隱藏一個div並顯示其他,但是當div顯示動畫停止時,我的問題是什麼,我的代碼Jquery Simple ScreenSaver

var mousetimeout; 
var screensaver_active = false; 
var idletime = 5; 

var screenSaver = $("#screenSaverForm"); 
var formDiv = $("#bodyForm"); 

function show_screensaver() { 
    formDiv.fadeOut(100); 
    screenSaver.fadeIn(900); 
    screensaver_active = true; 
} 

function stop_screensaver() { 
    screenSaver.fadeOut(100); 
    formDiv.fadeIn(900); 
    screensaver_active = false; 
} 

$(document).mousemove(function() { 
    clearTimeout(mousetimeout); 

    if (screensaver_active) { 
     stop_screensaver(); 
    } 

    mousetimeout = setTimeout(function() { 
     show_screensaver(); 
    }, 1000 * idletime); // 5 secs   
}); 

和申報單:

<div id="screenSaverForm" style="background-image: url(../../Content/img/screensavers.jpg); position: absolute; width: 100%; height:100%; left:0px; top: 0px; display: none; z-index:9999; display: none;">Example of a DIV element with a background image:</div> 

其他分區很簡單,如果有任何可以幫助,顯示動畫之前我需要重新加載頁面,任何知道如何做到這一點?

回答

0

您可以嘗試在stop_screensaver()之前添加此行;

. 
... 
if (screensaver_active) { 
    location.reload(); //Refreshes the page 
    stop_screensaver(); 
} 
... 
. 

或者,如果你只是想滾動到頁面頂部:

. 
... 
if (screensaver_active) { 
    $(window).scrollTop(0); //Scroll to top of page 
    stop_screensaver(); 
} 
... 
. 
+0

但是當一個DIV正在有關動畫平放看到什麼?我不會移動我的鼠標,但它的停止,是什麼原因? – NoNameR