【问题标题】:Load new content when user scrolls to the bottom using Dojo?当用户使用 Dojo 滚动到底部时加载新内容?
【发布时间】:2012-05-17 14:06:48
【问题描述】:

当用户到达底部时在 HTML 页面中加载新内容非常流行(FB、G+、Twitter),所以我也想在 XPages(它使用 Dojo)中实现它。看着SO(和附近)我发现有关JQuery和/或通用hereherehereherehereherehere和@的问题987654329@ 和 here,仅举几例。

但是如何在 Dojo 中做到这一点?

【问题讨论】:

  • just to name a few. 在我看来这不是a few

标签: javascript html dom dojo xpages


【解决方案1】:

很遗憾,我无法评论 Niklas 的回答,但他的回答是正确的。我要更改的一件事是在您滚动到底部而不是调用特定函数的情况下发出 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);    

(出于性能考虑,我还冒昧地进行了一些重构,因为我们只需要在到达页面底部时重新计算高度)。

这将允许您在代码中的其他位置挂钩此事件,而无需编辑此 sn-p 或覆盖 onMoreButtonClick() 函数。

【讨论】:

    【解决方案2】:

    我不知道 Dojo 是如何做到的,但您可以使用纯 JavaScript DOM API 做到这一点。

    我已经在移动控件中完成了这项工作。查看 http://www.openntf.org/Projects/pmt.nsf/downloadcounter?openagent&project=XPages%20Mobile%20Controls&release=4.5.0&unid=2D4F47CB07AAEE4086257887004ED6C5&attachment=MobileControls450.zip 的 MobileControlsLite.nsf(mView.xsp 和 mobileControls.js)

    以下是我应用中的一些 sn-ps:

    function scrollingDetector() {
        ...
    
        var pos = window.pageYOffset;
        var max = document.documentElement.scrollHeight - document.documentElement.clientHeight;
    
        if (max - 80 < pos) {   
            onMoreButtonClick(...);
        }
    }   
    
    setInterval(scrollingDetector, 500);    
    

    【讨论】:

    • 谢谢。现在我的清单上的任务:“自动扩展视图控制”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多