决定向下和向上滚动

Determining downward and upward scrolling

本文关键字:滚动 决定      更新时间:2023-09-26

我有一个sapui5表,如果表正在向上或向下滚动,我正试图登录控制台。我可以让它工作,如果我使用一个常规的div。

例子。

但是我似乎不能让它在sapui5表上工作。我尝试了以下操作:

var lastScroll = 0;
$("#__xmlview0--players-vsb-sb").scroll(function () {
    var st = $(this).scrollTop();
    if (st > lastScroll) {
        console.log("scrolling down");
    } else {
       console.log("scrolling up");
    }
    lastScroll = st;
});

当我检查滚动条上的元素时,我得到了id #__xmlview0--players-vsb-sb。我应该用这个id。有什么办法让它工作吗?

如果将滚动事件放入setTimout中,它将开始工作。

        setTimeout(function(){  

        var lastScroll = 0;
        $("#__xmlview0--players-vsb-sb").scroll(function () {
                var st = $(this).scrollTop();
                if (st > lastScroll) {
                    console.log("scrolling down");
                } else {
                    console.log("scrolling up");
                }
                lastScroll = st;
            });
}, 700);

这表明UI库在初始化元素上自己的事件时,正在清除它使用的元素上的事件。这可能是为了消除内存泄漏的风险。我建议不要使用超时,并查看此堆栈以获取更多信息:sapui5 -每次显示视图时调用哪个方法?