ASP.NET,c#制作在网页游动的层

来源:互联网 发布:南京农业大学网络课程 编辑:程序博客网 时间:2024/05/01 09:39
一,在<head></head>之间加
<style type="text/css">
div#pic1{
font-size:14px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-weight:bold;
border:solid 1px #777;
background:#cf9;
color:#f30;
line-height:2;
}
</style>
   <SCRIPT   LANGUAGE="JavaScript">  
  var   isNS   =   ((navigator.appName   ==   "Netscape")   &&   (parseInt(navigator.appVersion)   >=   4));  
  var   _all   =   '';  
  var   _style   =   '';  
  var   wwidth,   wheight;  
  var   ydir   =   '++';  
  var   xdir   =   '++';  
  var   id1,   id2,   id3;  
  var   x   =   1;  
  var   y   =   1;  
  var   x1,   y1;  
  if(!isNS)   {  
  _all='all.';  
  _style='.style';  
  }  
  function   getwindowsize()   {  
  clearTimeout(id1);  
  clearTimeout(id2);  
  clearTimeout(id3);  
  if   (isNS)   {  
  wwidth   =   window.innerWidth   -   55;  
  wheight   =   window.innerHeight   -   50;  
  }   else   {  
  wwidth   =   document.body.clientWidth   -   55;  
  wheight   =   document.body.clientHeight   -   50;  
  }  
  id3   =   setTimeout('randomdir()',   20000);  
  animate();  
  }  
  function   randomdir()   {  
  if   (Math.floor(Math.random()*2))   {  
  (Math.floor(Math.random()*2))   ?   xdir='--':   xdir='++';  
  }   else   {  
  (Math.floor(Math.random()*2))   ?   ydir='--':   ydir='++';  
  }  
  id2   =   setTimeout('randomdir()',   20000);  
  }  
  function   animate()   {  
  eval('x'+xdir);  
  eval('y'+ydir);  
  if   (isNS)   {  
  pic1.moveTo((x+pageXOffset),(y+pageYOffset))  
  }   else   {  
  pic1.pixelLeft   =   x+document.body.scrollLeft;  
  pic1.pixelTop   =   y+document.body.scrollTop;  
  }  
  if   (isNS)   {  
  if   (pic1.top   <=   5+pageYOffset)   ydir   =   '++';  
  if   (pic1.top   >=  400+wheight+pageYOffset)   ydir   =   '--';  
  if   (pic1.left   >=  -200+wwidth+pageXOffset)   xdir   =   '--';  
  if   (pic1.left   <=   5+pageXOffset)   xdir   =   '++';  
  }   else   {  
  if   (pic1.pixelTop   <=   5+document.body.scrollTop)   ydir   =   '++';  
  if   (pic1.pixelTop   >=  -400+wheight+document.body.scrollTop)   ydir   =   '--';  
  if   (pic1.pixelLeft   >=  -200+wwidth+document.body.scrollLeft)   xdir   =   '--';  
  if   (pic1.pixelLeft   <=   5+document.body.scrollLeft)   xdir   =   '++';  
  }  
  id1   =   setTimeout('animate()',   30);  
  }
function stop()
{
clearTimeout(id1);  
  clearTimeout(id2);  
  clearTimeout(id3);
}
   function closediv()
{
  pic1.display="none";
}
function start()
{
animate();
}
  </script>  






二,<body>里加上
  onLoad=“getwindowsize()”onresize=“getwindowsize()” topmargin="0"

三,在<body></body>之间写上自己的层就可以了
  <div   id="pic1"   style="position:absolute;   left:0px; top:0px;   z-index:auto; width:200px;"   >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="right"><a  href="javascript:closediv()">关闭</a></td>
  </tr>
  <tr>
    <td>
       这里写层里边的内容</td>
  </tr>
</table>
</div>
<script   type="text/javascript">  
  var  pic1=eval('document.'+_all+'pic1'+_style);  
  </script> 
原创粉丝点击