[英]Is there a way to only show a div when a user is scrolling?
我正在努力使它只在用戶滾動時顯示div。 當他們停止滾動時,div淡出。
我用Google搜索了各種術語,但也許我的條款不正確,因為返回的結果是在某個高度顯示div。
有什么建議么?
var myTimeout = -1; // Var to store a timeout reference in
$(window).scroll(function() { // When the user scrolls the window
$('#myDiv').show(); // Show the div (Any element)
if(myTimeout !== -1){ // If a timeout is running
clearTimeout(myTimeout); // Clear that timeout
}
myTimeout = setTimeout(function(){ // Set a timeout to hide the div
$('#myDiv').hide(); // Function that hides the div
}, 1000); // Run the function after 1 sec (1000 ms)
});
這段代碼在用戶開始滾動時顯示div,然后在用戶停止滾動后隱藏它1秒。
通過jQuery Mobile
$(document).on("scrollstop",function(){
alert("Stopped scrolling!");
});
$(document).on("scrollstart",function(){
alert("Started scrolling!");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.