2015-08-14 73 views
0

如何在鼠標滾動到特定位置時產生效果?如何使用滾動到頂部功能使用jQuery

<div id="target"> 
    <!-- some data here --> 
</div> 

jQuery的

var target = $('#target'); 

if(target.scrollTop() > 10){ 
    alert(''); 
} 
+3

你怎麼看'target.height('10px')'呢? – epascarello

+0

剛剛編輯我的問題請檢查 – Daniel

+0

您是指鼠標滾動時還是窗口滾動時? –

回答

0

您可能必須選擇,而不只是一個特定的div滾動功能完整的HTML文檔,

jQuery的

$(document).scroll(function(){ 
    if ($(window).scrollTop() > 10){ 
     // if the current scroll of the window is greater than 10px 
    alert(''); 
} 
});