5

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?

guest86
  • 2,894
  • 8
  • 49
  • 72

1 Answers1

10

Remove the onScroll from your body tag, and try adding

window.onscroll = Scroll;

to your javascript, outside of the function.

Scott
  • 675
  • 8
  • 19
  • Well, now function "Scroll()" gets called, but div is not moving :\ – guest86 Jan 17 '11 at 10:59
  • 3
    Your div isn't moving because `document.body.scrollTop` doesn't exist in IE. Please see this question for a solution to this: http://stackoverflow.com/questions/2717252/document-body-scrolltop-is-always-0-in-ie-even-when-scrolling – Nicklas A. Mar 08 '12 at 20:25