我从网上找到一段对联广告代码,单独执行这段代码时,当垂直滚动条滚动时,对联会固定在屏幕两侧的固定位置上,但是,当我把代码嵌入到我的页面时,随着垂直滚动条的移动,对联也跟着移动,不知道哪里问题。html部分:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS打造可关闭的对联广告代码 - www.webdm.cn</title>
</head>
<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div style="height:3000px;"></div>
<script language=JavaScript src="js/js.js"></script>
</BODY></HTML>
js部分:suspendcode = "<DIV id=lovexin1 style='Z-INDEX:10; LEFT:6px;  POSITION:absolute;TOP:105px;width:100;height:300px;'><img src='./img/close.gif' onClick='javascript:window.hide()' width='100' height='14' border='0' vspace='3' alt='关闭'><a href='#' target='_blank'><img src='./img/ad_100x300.jpg' width='100' height='300' border='0'></a></DIV>"
document.write(suspendcode);suspendcode = "<DIV id=lovexin2 style='Z-INDEX:10; RIGHT:6px; POSITION:absolute;TOP:105px;width:100;height:300px;'><img src='./img/close.gif' onClick='javascript:window.hide()' width='100' height='14' border='0' vspace='3' alt='关闭'><a href='#' target='_blank'><img src='./img/ad_100x300.jpg' width='100' height='300' border='0'></a></DIV>"
document.write(suspendcode);//flash格式调用方法
//<EMBED src='flash.swf' quality=high  WIDTH=100 HEIGHT=300 TYPE='application/x-shockwave-flash' id=ad wmode=opaque></EMBED>lastScrollY = 0;
function heartBeat() {
    diffY = document.body.scrollTop;
    percent = .3 * (diffY - lastScrollY);
    if (percent > 0) percent = Math.ceil(percent);
    else percent = Math.floor(percent);
    document.all.lovexin1.style.pixelTop += percent;
    document.all.lovexin2.style.pixelTop += percent;
    lastScrollY = lastScrollY + percent;
}
function hide() {
    lovexin1.style.visibility = "hidden";
    lovexin2.style.visibility = "hidden";
}
window.setInterval("heartBeat()", 1);

解决方案 »

  1.   


     
    <!doctype html>
    <html dir="ltr" lang="zh-CN">
      <head>
        <meta charset="utf-8"/>
        <title>CSS Position Fixed for IE6</title>
        <style>
    * html,* html body   {background-image:url(about:blank);background-attachment:fixed;}
    * html .fixed-top    {position:absolute;bottom:auto; top:expression(eval(document.documentElement.scrollTop +(document.documentElement.clientHeight-this.offsetHeight)/2 ));}
    * html .fixed-right  {position:absolute;right:0px;left:auto;}
    * html .fixed-bottom {position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));}
    * html .fixed-left   {position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft));}
    .fixed-bottom  {
      position:fixed;
      left:0px;
      bottom:20px;
      background:aqua;
      width:200px;
      height:200px;
    }
    .fixed-right{
      position:fixed;
      right:0px;
      left:auto;
      top:200px;
      top:expression(eval(document.documentElement.scrollTop +(document.documentElement.clientHeight-this.offsetHeight)/2 ));
      background:red;
      width:200px;
      height:200px;
    }
    .fixed-top{
      position:fixed;
      top:0px;
      left:0px;
      background:blue;
      width:200px;
      height:200px;
    }
        </style>  </head>
      <body>
      <div style='height:2000px;width:500px;margin:10px auto; border:1px solid red;'></div>
       <div class="fixed-top"></div>
        <div class="fixed-bottom"></div>
         <div class="fixed-right"></div>
        
      
      </body>
    </html>