使用 Dart 检测滚动到页面底部
Detect the scrolling to bottom of the page using Dart
我可以使用 Javascript
检测到滚动条到达底部
$(window).on("scroll", function() {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
// when scroll to bottom of the page
}
});
但我在 Dart 中找不到 document.height。
如何获取文档的高度并与 window.scrollY 进行比较?
我想,虽然我总是难以理解各种高度,但 document.body.clientHeight
应该可以(即我已经使用过一次)
_updateScrollInfo([_]) {
if (window.innerHeight + window.scrollY >= document.body.clientHeight) {
print("at bottom");
}
}
window.onScroll.listen(_updateScrollInfo);
DartPad 示例:https://dartpad.dartlang.org/6fcfb715e4090a1aafe4
我可以使用 Javascript
检测到滚动条到达底部$(window).on("scroll", function() {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
// when scroll to bottom of the page
}
});
但我在 Dart 中找不到 document.height。 如何获取文档的高度并与 window.scrollY 进行比较?
我想,虽然我总是难以理解各种高度,但 document.body.clientHeight
应该可以(即我已经使用过一次)
_updateScrollInfo([_]) {
if (window.innerHeight + window.scrollY >= document.body.clientHeight) {
print("at bottom");
}
}
window.onScroll.listen(_updateScrollInfo);
DartPad 示例:https://dartpad.dartlang.org/6fcfb715e4090a1aafe4