简体   繁体   中英

onscroll won't work with IE

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?

Remove the onScroll from your body tag, and try adding

window.onscroll = Scroll;

to your javascript, outside of the function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM