我正在嘗試execute only once,但它正在執行多次。我alert在用戶滾動時到達頁面的 90%時顯示。但它多次顯示警報。
我也試過:-
- 通過將陳述句轉為
true執行后。
但它沒有奏效。
頁面.html
var percent = 90;
var window_scrolled;
$(window).scroll(function() {
window_scrolled = ($(document).height()/100)*90;
if($(window).scrollTop() $(window).height() >= window_scrolled) {
var excuted = false
if (!excuted) {
alert("scrolled to bottom");
excuted = true
}
}
});
任何幫助將非常感激。謝謝你
uj5u.com熱心網友回復:
你總是設定false的excuted每一次,所以它始終運行。
嘗試這個:
var excuted = false
$(window).scroll(function() {
window_scrolled = ($(document).height()/100)*90;
if($(window).scrollTop() $(window).height() >= window_scrolled) {
if (!excuted) {
alert("scrolled to bottom");
excuted = true
}
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/354074.html
標籤:javascript html 查询
上一篇:如何在整個div上制作搜索過濾器
