Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
January Johnson
23,855 Pointsscrollstop() firing before reaching the bottom
I have a simple function, I think. I want to detect when the user reaches the bottom of a document when scrolling and if the bottom is reached execute code. Like this:
$(window).on('scrollstop', function(){
var a = $(window).scrollTop();
var b = $(window).innerHeight();
var c = $(document).innerHeight();
if (a == (c - b)) {
morepics();
}
});
The problem is instead of firing only when a == bottom, it fires at the first scroll stop. So if I scroll a little and then stop it fires. Can anyone help. --tested on android--
2 Answers
Colin Bell
29,679 PointsAre you looking for something like this?
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
Credit: Stack Overflow
January Johnson
23,855 PointsThanks!