2014-09-02 64 views
-3

我正在一個web項目上工作,客戶端要求我這樣做,只要光標懸停在頁面之外,就像用戶將光標移動到任務欄,標題欄等那麼整個頁面網站內容應該用封面屏幕替換。用壁紙替換整個網站的內容

我想我可以使用jQuery來跟蹤屏幕內的鼠標。如果光標移出屏幕,我可以將整個屏幕的顯示設置爲無,並在整個屏幕上顯示封面圖像。使用mouseleave(),mouseenter()函數。

但問題是我對jQuery並不熟悉。幫我編寫代碼。

+0

*替換*的內容,或*隱藏*內容通過顯示在上面的圖像的內容?順便說一下,如果你不熟悉jQuery,爲什麼不用普通的JavaScript來嘗試呢?我們會很高興地幫助你,但我們不會爲你做你的工作。 – 2014-09-02 05:39:12

+0

嗨...不幸的是,你不是一個代碼寫作服務。我建議谷歌搜索可能更有用。 – 2014-09-02 05:39:20

回答

0

您只需在mouseentermouseleave上使用toggleClass即可。

$('body').toggleClass('no-mouse'); 
$(document).on('mouseenter mouseleave', function() { 
    $('body').toggleClass('no-mouse'); 
}); 

CSS

.no-mouse { 
    background:red; 
} 

Demo

編輯


更新您的評論答案基地,

HTML,

<div class="wrapper test">website content</div> 
<div class="no-mouse test">without mouse image or color container.</div> 

JS

$(document).on('mouseenter mouseleave', function() { 
    $('.test').toggle(); 
}); 

CSS

.wrapper { 
    width:100%; 
    height:500px; 
    background:green; 
    margin:0px;  
    display: none; 
} 
.no-mouse { 
    position :absolute; 
    width:100%; 
    height:500px; 
    background:red; 
} 
body { 
    margin:0px; 
} 

Demo

+0

Thanks.But這隻會改變背景。如果我想用顏色或圖像替換網站的全部內容怎麼辦? – 2014-09-02 06:15:08

+0

@ShashankGaurav,請檢查更新後的答案 – 2014-09-02 06:48:39

+0

謝謝但是,只要光標離開屏幕然後返回內容,最後一個幫助就會自動滾動。就像如果我正在閱讀文章並將光標移出然後回來,它會自動滾動到頂部。我希望滾動條保持在光標重新進入區域時的位置。 – 2014-09-02 10:35:44