<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
body{ background-color:#999999; height:1200px;}
#advLayer{ position:absolute; top:20px; left:20px; background:url(img/01.jpg) no-repeat top left; width:80px; height:130px; z-index:1}
</style>
<script language="javascript">
  var adtop=0;
  function move(){
   document.getElementById('advLayer').style.pixelTop=adtop+document.body.scrollTop;
  }
  window.onscroll=move;
</script>
</head><body><div id="advLayer"></div>
</body>
</html>我写了个简单的 随着滚动条移动的 浮动广告!!
但是无法 随着滚动条移动!!!

解决方案 »

  1.   

    去掉下面的代码
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    这个规范换成<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">这个也可以
      

  3.   


    document.getElementById('advLayer').style.marginTop += document.documentElement.scrollTop + "px";但是需要刷新页面
      

  4.   

    http://www.360doc.com/content/05/1121/12/777_33768.shtml
    看看这个
      

  5.   


    document.getElementById('advLayer').style.top = 20 +adtop+document.documentElement.scrollTop +"px";这样在ff下可以