[分享]图片在网页中的游动效果(游来游去的广告,也可以说是浮动)
huangjin需要鼠标悬停的,恰好论坛后台有这个广告开关,就把相应的js文件拿出来替换掉刚才的那个,这个优化的比较好.
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var vmin=2; //移动的最小速度
var vmax=5; //移动的最大速度
var vr=3;
var timer1;
var jobads;
function move_ad(Forum_ads_3,Forum_ads_4,Forum_ads_5,Forum_ads_6)
{
document.write('<div id="jobads" style="height:49px;left:178px;position:absolute;top:1237px;width:70px; z-index:1000">');
document.write('<a href="' + Forum_ads_4 + '" target="_blank" onmouseover=stopme("jobads"); onmouseout=movechip("jobads");>');
document.write('<img src="' + Forum_ads_3 + '" border="0" width="' + Forum_ads_5 + '" height="' + Forum_ads_6 + '"></a></div>');
jobads();
}
function jobads()
{
if(navigator.appName.indexOf("Internet Explorer")!=-1)
{
if(parseInt(navigator.appVersion.substring(0,1))>=4) brOK=navigator.javaEnabled();mie=true;
}
if(navigator.appName.indexOf("Netscape")!=-1)
{
if(parseInt(navigator.appVersion.substring(0,1))>=4) brOK=navigator.javaEnabled();
}
jobads.named="jobads";
jobads.vx=vmin+vmax*Math.random();
jobads.vy=vmin+vmax*Math.random();
jobads.w=1;
jobads.h=1;
jobads.xx=0;
jobads.yy=0;
jobads.timer1=null;
movechip("jobads");
}
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.xx>=680)
{
chip.xx=chip.xx-20;
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+"')",80);
}
}
function stopme(chipname)
{
if(brOK)
{
eval("chip="+chipname);
if(chip.timer1!=null)
{
clearTimeout(chip.timer1)
}
}
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT language=javascript>move_ad('Images/userface/image21.gif','/bbs/index.asp','100','100');</SCRIPT>
</BODY>
</HTML>
[此贴子已经被作者于2005-1-20 13:15:20编辑过]