$(window).scrollTop() vs. $(document).scrollTop()
What’s the difference between:
They are both going to have the same effect.
However, as pointed out in the comments:
$(window).scrollTop() is supported by more web browsers than
window.document.bgcolor = "red"
To answer your question, There is No difference in the end result between window and document scrollTop. Both will give the same output.
Check working example at http://jsfiddle.net/7VRvj/6/
In general use document mainly to register events and use window to do things like scroll, scrollTop, and resize.
Cross browser way of doing this is
var top = ($(window).scrollTop() || $("body").scrollTop());
I’ve just had some of the similar problems with
scrollTop described here.
In the end I got around this on Firefox and IE by using the selector
Not perfect if you have elements you don’t want to effect but it gets around the Document, Body, HTML and Window disparity. If it helps…