一个网页里的一张图片随即在网页里移动..那个是怎么实现的
发布网友
发布时间:2022-04-25 19:24
我来回答
共6个回答
热心网友
时间:2022-04-25 20:53
<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=2;
var vmax=5;
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)
{//alert(chipname)
eval("chip="+chipname);
if(chip.timer1!=null)
{clearTimeout(chip.timer1)}
}
} </SCRIPT>
<SCRIPT>
var mm;
function mm()
{checkbrOK();
mm=new Chip("mm",60,80);
if(brOK)
{ movechip("mm");
}
}
</SCRIPT>
</head>
<body onload=mm()>
<p> <DIV id=mm style="POSITION: absolute">
<img border="0" src="http://chenzujian.ik8.com/img/ad1.gif" width="100" height="100"></p>
热心网友
时间:2022-04-25 22:11
你好,
可以在图片上面放置n个透明div,并为每个div设置title属性,而title就是该图片区域的描述,当标放在div之上时就会自动弹出title的提示,,注意div需要定位到合适的位置。。。。。。。
ps
:如果需要显示出一个自定义样式的文本框,原理也是一样的,你可以先把文本框做好,默认隐藏,当光标经过时显示出来。。。。。。。。当然这个效果结合js用插入节点的方式来做会更好些。。。。
热心网友
时间:2022-04-25 23:46
用JAVASCRIPT实现的,可以搜索一下这样的JS代码,“随机移动的层”或“浮动的层”,或JAVASCRIPLT特效代码,很多的。
热心网友
时间:2022-04-26 01:37
不是flash做的 可以用dw实现也可以用javascript脚本嵌入到网页!移动的图片可以是flash也可以是普通的图片
热心网友
时间:2022-04-26 03:45
<DIV id=ad style="POSITION: absolute">
<A href="index.htm" target=_blank><IMG src='./2_bjycrdtu.jpg' border='0'> </A>
</DIV>
<SCRIPT>
var x = 50,y = 60
var xin = true, yin = true
var step = 1
var delay = 100
var obj=document.getElementById("ad")
function floatAD() {
var L=T=0
var R= document.body.clientWidth-obj.offsetWidth
var B = document.body.clientHeight-obj.offsetHeight
obj.style.left = x + document.body.scrollLeft
obj.style.top = y + document.body.scrollTop
x = x + step*(xin?1:-1)
if (x < L) { xin = true; x = L}
if (x > R){ xin = false; x = R}
y = y + step*(yin?1:-1)
if (y < T) { yin = true; y = T }
if (y > B) { yin = false; y = B }
}
var itl= setInterval("floatAD()", delay)
obj.onmouseover=function(){clearInterval(itl)}
obj.onmouseout=function(){itl=setInterval("floatAD()", delay)}
</SCRIPT>
<!--票动广告代码-------------------->
热心网友
时间:2022-04-26 06:10
就楼上这个了