jQuery scrolltop firefox not working

seanlevan picture seanlevan · Jul 21, 2013 · Viewed 35.1k times · Source

This script:

function onscroll(){
    document.getElementById("divs").style.top=""+$('body').scrollTop()+"px";
}

Fiddle: http://jsfiddle.net/Hed2J/1/

Doesn't work on the latest Firefox version!

What am I doing wrong? :) Thanks for the help!

Edit: Edited with JSFiddle and full script :) as attached to an onscroll event

Answer

Lucas Willems picture Lucas Willems · Jul 21, 2013

Try this fiddle, it is working in chrome, ie and the latest version of mozilla : http://jsfiddle.net/Hed2J/3/

I replace $('body').scrollTop() with $(window).scrollTop().