CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2018-08-26
by BloodyMonkey

Original Post

Original - Posted on 2012-05-29
by Miles O'Keefe



            
Present in both answers; Present only in the new answer; Present only in the old answer;

For compatibility on all browsers, try [this method][1]
function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }
Replace `$(document).height()` by this function and it's all good
$(window).scroll(function() { if($(window).scrollTop() + $(window).height() == getDocHeight()) { alert("bottom!"); } });

[1]: https://j11y.io/javascript/get-document-height-cross-browser/
Nick Craver's answer works fine, spare the issue that the value of `$(document).height()` varies by browser.
To make it work on all browsers, use this function from [James Padolsey][1]:
function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }
in place of `$(document).height()`, so that the final code is:
$(window).scroll(function() { if($(window).scrollTop() + $(window).height() == getDocHeight()) { alert("bottom!"); } });
[1]: http://james.padolsey.com/javascript/get-document-height-cross-browser/

        
Present in both answers; Present only in the new answer; Present only in the old answer;