javascript onscroll 不适用于 IE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4709673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
onscroll won't work with IE
提问by guest86
i have a "body" with onScroll="Scroll()". Scroll method should, well, scroll some div as user scrolls the page.
我有一个“身体” onScroll="Scroll()"。Scroll 方法应该在用户滚动页面时滚动一些 div。
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?
它适用于 Chrome 和 FF,但 IE 不会合作。这里有什么问题?
回答by Scott
Remove the onScroll from your body tag, and try adding
从你的 body 标签中删除 onScroll,然后尝试添加
window.onscroll = Scroll;
to your javascript, outside of the function.
到您的 javascript,在函数之外。

