教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 漂浮广告的经典js代码

漂浮广告的经典js代码

发布时间:2015-07-08   编辑:jiaochengji.com
本文介绍了js漂浮广告代码的实现方法,一个经典的漂浮广告的js代码,有需要的朋友参考下,希望对大家有所帮助。

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

复制代码 代码示例:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>漂浮广告代码_www.jiaochengji.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>

您可能感兴趣的文章:
漂浮广告的经典js代码
js漂浮广告代码大全
js全屏漂浮广告代码 移入光标停止移动
js漂浮广告代码示例
JS全屏漂浮广告、移入光标停止移动
js右侧漂浮广告的小例子
js漂浮广告代码 js弹性漂浮广告
js实现漂浮广告效果的代码
JS全屏漂浮广告代码
Js全屏漂浮广告效果的代码示例

关键词: 漂浮广告代码   
[关闭]
~ ~