I am working on a website, which has scroll to BOTTOM to load AJAX content.
I use this Jquery Scroll function:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height())
{
alert("ScrollTop + Window Height = "+$(window).scrollTop()+ " + " +
$(window).height()+ " == Document Height = "+$(document).height());
// This get's alerted only when i reach TOP
}
});
But this works only if i reach TOP
Do anyone had this problem before ?
You can try following code for your issue.
$(window).scroll(function() {
if($(window).scrollTop() == $(document).height() -$(window).height())
{
load_data();
}
});
And for more information visit this Link
First you need to understand defference between window and document for example 800wX600h ($(window).scrollTop() + $(window).height() == $(document).height()
0+600=600
So it should be 0+600 > 600
replace it with ($(window).scrollTop() + $(window).height() == $(document).height()
I found a solution for this issue,
Its My Mistake that, i didn't include doc type in my html code.
<!DOCTYPE html>
And that's why the scroll worked in reverse order. After including the doctype at the 1st line of the code, it's working good as expected (ie) Scrolling to the bottom of page to load more AJAX content or call function().
So when ever you write a code start with < !DOCTYPE html >
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.