我有一个 sapui5 表,如果该表向上或向下滚动,我将尝试登录控制台。如果我使用常规 div,我就可以让它工作。
示例 here .
但我似乎无法让它适用于 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。关于如何让它发挥作用有什么想法吗?
这是我的 JSBin .
最佳答案
如果将滚动事件放入 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-Which method to call once a view is displayed everytime?
关于javascript - 确定向下和向上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31568749/