Xeen
Xeen

Reputation: 7003

jQuery alternative to scrollTop?

I need to detect how far from top the document has been scrolled and for that I used scrollTop(). Unfortunatelly it doesn't work on some versions of Android and therefor I need a different solution. Is there a way I could get the $(document).scrollTop without scrollTop function?

Upvotes: 4

Views: 2679

Answers (2)

Bojan Kseneman
Bojan Kseneman

Reputation: 15668

This worked for me, hope it works for you too

 var body = document.body;
 var docElem = document.documentElement;
 var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;

Upvotes: 6

David Passmore
David Passmore

Reputation: 6099

You can try window.pageYOffset to determine the offset from the top. E.G:

alert(window.pageXOffset + window.pageYOffset);

Upvotes: 0

Related Questions