onscroll won't work with IE

guest86 picture guest86 · Jan 17, 2011 · Viewed 16.8k times · Source

i have a "body" with onScroll="Scroll()". Scroll method should, well, scroll some div as user scrolls the page.

Scroll():

function Scroll()
{
    var el = document.getElementById('controlBox');
    var ScrollTop = document.body.scrollTop;
    el.style.top = ScrollTop + "px";
}

It works fine with Chrome and FF, but IE won't cooperate. What's wrong here?

Answer

Scott picture Scott · Jan 17, 2011

Remove the onScroll from your body tag, and try adding

window.onscroll = Scroll;

to your javascript, outside of the function.