迅腾网络>圈子>建站知识> 迅腾网络分享一个满屏飞动的图片代码

迅腾网络分享一个满屏飞动的图片代码

热度:11445 / 2012-11-2 / 廊坊网站建设 / 建站知识

满屏飞动的图片代码

var xPos = 300;
var yPos = 200;
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
img1.style.top = yPos;
function changePos()
{
 width = document.body.clientWidth;
 height = document.body.clientHeight;
 Hoffset = img1.offsetHeight;
 Woffset = img1.offsetWidth;
 img1.style.left = xPos + document.body.scrollLeft;
 img1.style.top = yPos + document.body.scrollTop;
 if (yon)
  {yPos = yPos + step;}
 else
  {yPos = yPos - step;}
 if (yPos < 0)
  {yon = 1;yPos = 0;}
 if (yPos >= (height - Hoffset))
  {yon = 0;yPos = (height - Hoffset);}
 if (xon)
  {xPos = xPos + step;}
 else
  {xPos = xPos - step;}
 if (xPos < 0)
  {xon = 1;xPos = 0;}
 if (xPos >= (width - Woffset))
  {xon = 0;xPos = (width - Woffset);   }
 }
 
 function start()
  {
   img1.visibility = "visible";
  interval = setInterval('changePos()', delay);
 }
 function pause_resume()
 {
  if(pause)
  {
   clearInterval(interval);
   pause = false;}
  else
  {
   interval = setInterval('changePos()',delay);
   pause = true;
   }
  }
 start();

 

说明:把上面的代码另存为一个feidong.JS文件,然后在想实现此效果的页面用<script src="feidong.js"></script>调用即可

 

使用方法:


 
<DIV id=img1 style="Z-INDEX: 100; LEFT: 2px; WIDTH: 9px; POSITION: absolute; TOP: 3px; HEIGHT: 1px;
 visibility: visible;"><a href=www.web0316.cn><img src="http://www.web0316.cn/images/logo.jpg" border="0"></a></DIV>


    <SCRIPT src="feidong.js"></SCRIPT>
 
 

注意修改广告图片地址和连接地址!相应的参数可以根据页面自行调整。