简单的JavaScript在任何IE中都不起作用?

Rah*_*hah 11 html javascript css internet-explorer

我正在用这个代码创建一个轻微的视差效果.除了IE之外,一切都可以正常工作.我正在使用IE 9.

的jsfiddle的JavaScript

的jsfiddle-的jQuery

<div id="head"> i </div>
<div id="subHead"> can </div>
<div id="content">  haz </div>
Run Code Online (Sandbox Code Playgroud)

使用Javascript

window.onscroll = function(ev){
  var subHead = document.getElementById('subHead'),
      topHeight = document.getElementById('head').offsetHeight;

  subHead.style.top = (topHeight - document.body.scrollTop / 4) + 'px';
};    
Run Code Online (Sandbox Code Playgroud)

CSS

#head, #subHead{
    position: fixed;           
    height: 80px;    
    width: 100%;
    display: block;
    background: #c00;
    left: 0;
    top: 0;
    z-index: 10;
}

#subHead{
    z-index: 4;
    background: #cd0; 
    top: 80px;
}

#content{
    position: relative;
    z-index: 6;
    height: 1000px;
    background: #eee;
    margin-top: 160px;
}
Run Code Online (Sandbox Code Playgroud)

我试着谷歌搜索一些跨浏览器的技巧,但徒劳无功...有没有办法让它在IE中工作?非常感谢.

编辑:

目的:当用户滚动时,使1 div比另一个慢.

逻辑:通过CSS修复div并通过javascript http://jsfiddle.net/MRbWY/11/更改其位置

IE中的错误.javascript不起作用.因此div仍然是固定的

Emi*_*ary 3

document.body.scrollTop 总是读数为零,稍微挖掘一下就会发现这个问题,你想用于document.documentElement.scrollTopIE。

更新了你的小提琴