经典的页面漂浮广告代码
今天要做一个页面的漂浮广告,原先的几个都不好用,找了几个还算比较好的,跟大家分享。
一、经典常用页面漂浮广告代码
<script language="javascript">
document.write("<div id='ad' style='position:absolute; left:50px; top:800px'><a href='http://www.xiaoxiaoyu.net' target='_blank'><img src='http://www.xiaoxiaoyu.net/logo.gif' border='0'</a></div>");var xPos = 20;
var yPos = document.body.clientHeight;
var step = 1;
var delay = 20;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
ad.style.top = yPos;
function wbggchangePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = ad.offsetHeight;
Woffset = ad.offsetWidth;
ad.style.left = xPos + document.body.scrollLeft;
ad.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 wbggstart() {
ad.visibility = "visible";
interval = setInterval("wbggchangePos()", delay);
}
wbggstart();
</script>
二、页面漂浮广告代码
将以下代码放在<head></head>之间。
<SCRIPT language=JavaScript>
var brOK=false;
var mie=false;
var aver=parseInt(navigator.appVersion.substring(0,1));
var aname=navigator.appName;
function checkbrOK()
{if(aname.indexOf("Internet Explorer")!=-1)
{if(aver>=4) brOK=navigator.javaEnabled();
mie=true;
}
if(aname.indexOf("Netscape")!=-1)
{if(aver>=4) brOK=navigator.javaEnabled();}
}
var vmin=5;
var vmax=2;
var vr=2;
var timer1;
function Chip(chipname,width,height)
{this.named=chipname;
this.vx=vmin+vmax*Math.random();
this.vy=vmin+vmax*Math.random();
this.w=width;
this.h=height;
this.xx=0;
this.yy=0;
this.timer1=null;
}
function movechip(chipname) {
if(brOK)
{eval("chip="+chipname);
if(!mie)
{pageX=window.pageXOffset;
pageW=window.innerWidth;
pageY=window.pageYOffset;
pageH=window.innerHeight;
}
else
{pageX=window.document.body.scrollLeft;
pageW=window.document.body.offsetWidth-8;
pageY=window.document.body.scrollTop;
pageH=window.document.body.offsetHeight;
}
chip.xx=chip.xx+chip.vx;
chip.yy=chip.yy+chip.vy;
chip.vx+=vr*(Math.random()-0.5);
chip.vy+=vr*(Math.random()-0.5);
if(chip.vx>(vmax+vmin)) chip.vx=(vmax+vmin)*2-chip.vx;
if(chip.vx<(-vmax-vmin)) chip.vx=(-vmax-vmin)*2-chip.vx;
if(chip.vy>(vmax+vmin)) chip.vy=(vmax+vmin)*2-chip.vy;
if(chip.vy<(-vmax-vmin)) chip.vy=(-vmax-vmin)*2-chip.vy;
if(chip.xx<=pageX)
{chip.xx=pageX;
chip.vx=vmin+vmax*Math.random();
}
if(chip.xx>=pageX+pageW-chip.w)
{chip.xx=pageX+pageW-chip.w;
chip.vx=-vmin-vmax*Math.random();
}
if(chip.yy<=pageY)
{chip.yy=pageY;
chip.vy=vmin+vmax*Math.random();
}
if(chip.yy>=pageY+pageH-chip.h)
{chip.yy=pageY+pageH-chip.h;
chip.vy=-vmin-vmax*Math.random();
}
if(!mie)
{eval('document.'+chip.named+'.top ='+chip.yy);
eval('document.'+chip.named+'.left='+chip.xx);
}
else
{eval('document.all.'+chip.named+'.style.pixelLeft='+chip.xx);
eval('document.all.'+chip.named+'.style.pixelTop ='+chip.yy);
}
chip.timer1=setTimeout("movechip('"+chip.named+"')",100);
}
}
function stopme(chipname)
{if(brOK)
{
eval("chip="+chipname);
if(chip.timer1!=null)
{clearTimeout(chip.timer1)}
}}
var floater;
function floater()
{checkbrOK();
floater=new Chip("floater",0,0);
if(brOK)
{ movechip("floater");
}}
</SCRIPT>在body中添加:
<BODY bgColor=#debe9c leftMargin=0 topMargin=0 onload=floater()>
<DIV id=floater
style="Z-INDEX: 100; LEFT: 185px; WIDTH: 0px; POSITION: absolute; TOP: 73px; HEIGHT: 0px"><A
href="http://www.xiaoxiaoyu.net/" target=blank><IMG
src="welcome.jpg" border=0></A> </DIV>
</body>
三、一个页面漂浮多个广告
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>一个页面漂浮多个广告实例<b style="color:black;background-color:#a0ffff">漂浮</b><b style="color:black;background-color:#99ff99">广告</b>源代码</title>
<script language="javascript" type="text/javascript">
var Rimifon = {
"Ads" : new Object,
"NewFloatAd" : function(imgUrl, strLink)
{
var ad = document.createElement("a");
ad.DirV = true;
ad.DirH = true;
ad.AutoMove = true;
ad.Image = new Image;
ad.Seed = Math.random();
ad.Timer = setInterval("Rimifon.Float(" + ad.Seed + ")", 50);
this.Ads[ad.Seed] = ad;
ad.Image.Parent = ad;
ad.style.position = "absolute";
ad.style.left = 0;
ad.style.top = 0;
ad.Image.src = imgUrl;
ad.Image.onmouseover = function(){this.Parent.AutoMove = false;}
ad.Image.onmouseout = function(){this.Parent.AutoMove = true;}
if(strLink)
{
ad.href = strLink;
ad.Image.border = 0;
ad.target = "_blank";
}
ad.appendChild(ad.Image);
document.body.appendChild(ad);
return ad;
},
"Float" : function(floatId)
{
var ad = this.Ads[floatId];
if(ad.AutoMove)
{
var curLeft = parseInt(ad.style.left);
var curTop = parseInt(ad.style.top);
if(ad.offsetWidth + curLeft > document.body.clientWidth + document.body.scrollLeft - 1)
{
curLeft = document.body.scrollLeft + document.body.clientWidth - ad.offsetWidth;
ad.DirH = false;
}
if(ad.offsetHeight + curTop > document.body.clientHeight + document.body.scrollTop - 1)
{
curTop = document.body.scrollTop + document.body.clientHeight - ad.offsetHeight;
ad.DirV = false;
}
if(curLeft < document.body.scrollLeft)
{
curLeft = document.body.scrollLeft;
ad.DirH = true;
}
if(curTop < document.body.scrollTop)
{
curTop = document.body.scrollTop;
ad.DirV = true;
}
ad.style.left = curLeft + (ad.DirH ? 1 : -1) + "px";
ad.style.top = curTop + (ad.DirV ? 1 : -1) + "px";
}
}
}
</script>
</head>
<body>
<div style="height:800px"></div>
<script language="javascript" type="text/javascript">
Rimifon.NewFloatAd("http://www.baidu.com/img/baidu_logo.gif", "http://www.baidu.com/");
var ad = Rimifon.NewFloatAd("http://www.google.com/intl/zh-CN/logos/Logo_60wht.gif","http://www.google.com/");
ad.style.left = 400;
ad.style.top = 300;
ad.Image.width = 176;
ad.Image.height = 77;
</script>
</body>
</html>
0 条留言
我要留言