簡體   English   中英

當用戶使用Dojo滾動到底部時加載新內容嗎?

[英]Load new content when user scrolls to the bottom using Dojo?

當用戶到達底部時,在HTML頁面中加載新內容非常流行(FB,G +,Twitter),因此我也想在XPages(使用Dojo)中實現這一點。 在SO上(和附近),我發現有關JQuery和/或泛型的問題在這里這里這里這里這里這里這里這里這里這里 ,僅舉幾例。

但是在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM