sandbox
sandbox

Reputation: 2679

scrollTop stuck at zero

I am trying to get the vertical position on scroll of page but it is stuck at 0 value.

window.onscroll=f;
function f() {

document.getElementById('div1').innerHTML=document.body.scrollTop;
}

Upvotes: 0

Views: 787

Answers (2)

Sridhar Sarnobat
Sridhar Sarnobat

Reputation: 25246

In my case I was using document.documentElement.scrollTop when I should have been using window.pageYOffset.

Upvotes: 0

user160820
user160820

Reputation: 15220

try to use something like

document.getElementById('div1').innerHTML=document.documentElement.scrollTop ? 
document.documentElement.scrollTop : document.body.scrollTop

Upvotes: 1

Related Questions