js漂浮广告代码 js弹性漂浮广告

发布时间:2020-07-20编辑:脚本学堂
本文介绍了js物理性漂浮广告的代码,js漂浮广告的小例子,实现广告图处的全屏漂浮移动,有需要的朋友参考下。

1,js漂浮广告代码 js.js
 

复制代码 代码示例:
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();

2,html部分
 

复制代码 代码示例:
<body>
<div id=img1 style="z-index: 100; left: 2px; width: 59px; position: absolute; top: 43px; height: 61px;
 visibility: visible;"><a href="http://www.jb200.com/" target="_blank"><img src="images/pic.gif" width="80" height="80" border="0"></a></div>
<script src="js/js.js"></script>
</body>