![](/img/trans.png)
[英]How to load more content with ajax when user scrolls to the bottom the of page only once
[英]Load new content when user scrolls to the bottom using Dojo?
我不知道Dojo是如何做到的,但是您可以使用簡單的JavaScript DOM API來做到這一點。
我已經在移動控件中完成了此操作。 從http://www.openntf.org/Projects/pmt.nsf/downloadcounter?openagent&project=XPages%20Mobile%20Controls&release=4.5.0&unid=2D4F47CB07AAEE4086257887004ED6C5&attachment=MobileControl簽出MobileControlsLite.nsf(mView.xsp和mobileControls.js) 。
以下是我的應用程序中的一些片段:
function scrollingDetector() {
...
var pos = window.pageYOffset;
var max = document.documentElement.scrollHeight - document.documentElement.clientHeight;
if (max - 80 < pos) {
onMoreButtonClick(...);
}
}
setInterval(scrollingDetector, 500);
不幸的是,我無法評論尼克拉斯的答案,但他的答案是正確的。 我要更改的一件事是在滾動到底部而不是調用特定函數的情況下發出Dojo事件。
var scrollingDetector = (function() {
var max = calculateScrollHeight();
return function(){
if (max < window.pageYOffset) {
max = calculateScrollHeight();
dojo.publish('/newsApp/onScrollBottom');
}
}
function calculateScrollHeight(){
return (document.documentElement.scrollHeight - document.documentElement.clientHeight) - 80;
}
})();
setInterval(scrollingDetector, 500);
(出於性能的考慮,我還自由地進行了一些重構,因為當我們到達頁面底部時,我們只需要重新計算高度即可)。
這將使您能夠在代碼的其他位置插入該事件,而無需編輯此代碼片段或覆蓋onMoreButtonClick()函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.