scroll to bottom jquery not working properly

I have simple on code to see if bottom of page is reached alert. but its not working as I wanted.

I scroll down and come again to top, then is showing alert box. below is the code.

$(document).ready(function () {
    $(window).scroll(function () {
        if ($(window).scrollTop() + $(window).height() == $(document).height()) {
            alert("bottom!");
        }
    });
});

Answers


I finally came with this solution

$(window).scroll(function() {
  if (document.body.scrollHeight ==  document.body.scrollTop +  window.innerHeight) {
       alert("bottom!");

 }
});

Need Your Help

std::string declared function does not complain returning char *

c++ string

This is not my program so don't start berating me :-). Some random program I got. A globally declared buffer is being returned by MyFunc(). I use VS2008 and it does not complain

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.