日期:2014-05-16  浏览次数:20403 次

求助,写个个固定广告位的js网页,ie下没问题,其他火狐和chrom都实现不了
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#container{ margin-left:15%;}
#ad{ position:absolute; left:10px; top:90px; width:72px; height:130px; border:solid 1px gray; background-color:#eee; font-size:12px; cursor:pointer;}
#as div{ text-align:center;}
</style>
<script language="javascript">
  var _handler;
   
  window.onscroll=function(){
   
  if(_handler) window.clearTimeout(_handler);
  var ad=document.getElementById('ad');
  var y1=ad.offsetTop;
  //var y2=90+document.body.scorllTop;
  var y2=90+document.documentElement.scrollTop;
  //alert(y2);
  move(y1,y2);
  }
  function move(y1,y2){
  var ad=document.getElementById('ad');
if((y1+(y2-y1)/5)>=y2)
{
ad.style.top=y2;
_handler=null;
}
  else{
  y1+=(y2-y1)/5;
  ad.style.top=y1;
  _handler=window.setTimeout('move('+y1+','+y2+")",50);
  }
  }
  function close_onclick(){
  var ad=document.getElementById('ad');
ad.style.display='none';
ad.innerHTML='';
  }
  function ad_onclick(){
  window.location='www.google.com';
  }
</script>
</head>

<body style=" height:2000px;">
<div id="ad">
<img src="images/0916100.png" width="70px" onclick="ad_onclick()" />
<div onclick="close_onclick()">关闭</div>
</div>
<div id="container">
<img src="images/gif008.gif" />
</div>
</body>
</html>
求解答,如有什么好方法及思路可告知那更是感激不尽,本人还是新手

------解决方案--------------------
火狐下通过CLASS执行的TOP似乎取不到 ad.style.top为空 重新设置一下TOP似乎就可以了
JScript code

var _handler;
  window.onscroll=function(){
  if(_handler) window.clearTimeout(_handler);
  var ad=document.getElementById('ad');
  [color=#FF0000]if(!ad.style.top){ad.style.top="90px";}[/color]
  var y1=parseInt(ad.style.top);
  var y2=90+parseInt(document.documentElement.scrollTop);
  move(y1,y2);
  }
  function move(y1,y2){
  var ad=document.getElementById('ad');//ad.style.top=y2+"px";
if((y1+(y2-y1)/5)>=y2){
ad.style.top=y2+"px";
_handler=null;
}else{
  y1+=(y2-y1)/5;
  ad.style.top=y1+"px";
  _handler=window.setTimeout('move('+y1+','+y2+')',50);
  }
  }
  function close_onclick(){
  var ad=document.getElementById('ad');
ad.style.display='none';
ad.innerHTML='';
  }
  function ad_onclick(){
  window.location='www.google.com';
  }

------解决方案--------------------
被你搞到崩溃,还有特意要求这种效果的呢。我印象中的静止定位的意思是:它就在那里,一直都在,而不是你让他去那里。。。。算了,给出修正过后的代码吧:
JScript code
<script language="javascript">
  var _handler;
    
  window.onscroll=function(){
    
  if(_handler) window.clearTimeout(_handler);
  var ad=document.getElementById('ad');
  var y1=ad.offsetTop;
  //下面这句中document.body.scrollTop主要为了在Chrome中生效  
  var y2=document.documentElement.scrollTop==0?90+document.body.scrollTop:90+document.documentElement.scrollTop;
  

  move(y1,y2);
  }
  function move(y1,y2){
  var ad=document.getElementById('ad');
    if((parseFloat(y1)+parse