I have some JS/jQuery code on my page that is supposed to perform an action once the user has scrolled to the bottom of the page. Here's the code:
$(window).scroll(function () {
var position = $(document).scrollTop() + $(window).height();
if (position >= $(document).height()) {
// bottom is hit, do something
}
});
This works just fine in several browsers that I've tested:
The only one that it doesn't work on is Chrome for Android. It's been an issue for at least a little while, but currently on Chrome Android version 57.0.2987.132.
Any ideas?
You have a typo in your code.
if (position >= $(document).height()) {
// bottom is hit, do something
});
should be
if (position >= $(document).height()) {
// bottom is hit, do something
}
without the );
at the end.
Otherwise, your logic is fine, I tested it in Chrome for desktop as well as for Android.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.