码迷,mamicode.com
首页 > 其他好文 > 详细

随机漂浮图片广告实例代码

时间:2016-02-21 22:55:30      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>漂浮广告代码-蚂蚁部落</title>
<style type="text/css">
#thediv
{
z-index:100;
position:absolute;
top:43px;
left:2px;
height:100px;
width:100px;
background-color:red;
}
</style>
<script type="text/javascript">
var xPos=300;
var yPos=200;
var step=1;
var delay=8;
var height=0;
var Hoffset=0;
var Woffset=0;
var yon=0;
var xon=0;
var pause=true;
var interval;
function changePos()
{
width=document.documentElement.clientWidth;
height=document.documentElement.clientHeight;
Hoffset=thediv.offsetHeight;
Woffset=thediv.offsetWidth;
thediv.style.left=(xPos+document.body.scrollLeft+document.documentElement.scrollLeft)+"px";
thediv.style.top=(yPos+document.body.scrollTop+document.documentElement.scrollTop)+"px";
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()
{
thediv.visibility="visible";
interval=setInterval(‘changePos()‘,delay);
}
function pause_resume()
{
if(pause)
{
clearInterval(interval);
pause = false;
}
else
{
interval = setInterval(changePos,delay);
pause = true;
}
}
window.onload=function()
{
thediv.style.top=yPos;
start();
}
</script>
</head>
<body>
<div id="thediv"></div>
</body>
</html>

随机漂浮图片广告实例代码

标签:

原文地址:http://www.cnblogs.com/hgbgfg/p/5205724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!