漂浮广告的经典js代码

发布时间:2020-12-21编辑:脚本学堂
本文介绍了js漂浮广告代码的实现方法,一个经典的漂浮广告的js代码,有需要的朋友参考下,希望对大家有所帮助。

比较经典的浮动广告,js漂浮广告代码,站长朋友们可以借鉴下。
代码:
 

复制代码 代码示例:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>漂浮广告代码_www.jb200.com</title>
</head>
<body>
<div id=img1 style="z-index: 100; left: 2px; width: 59px; position: absolute; top: 43px; height: 61px;
 visibility: visible;"><a href="/jscss/" target="_blank"><img src="/jscss/demoimg/200908/pic.gif" width="80" height="80" border="0"></a></div>
<script>
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;
//js漂浮广告代码示例
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();
</script>
</body>
</html>