Reputation: 2679
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
Reputation: 25246
In my case I was using document.documentElement.scrollTop
when I should have been using window.pageYOffset
.
Upvotes: 0
Reputation: 15220
try to use something like
document.getElementById('div1').innerHTML=document.documentElement.scrollTop ?
document.documentElement.scrollTop : document.body.scrollTop
Upvotes: 1