跟随鼠标向上飘动的图片

效果演示http://www.home.sunbo.com/xfile.php?xname=686QF01&fname=/texiao/%B8%FA%CB%E6%CA%F3%B1%EA%CF%F2%C9%CF%C6%AE%B6%AF%B5%C4%CD%BC%C6%AC.html

将下列代码中的红色部分替换为你的图片地址即可,本代码适合做水中冒泡泡的效果哦

代码如下:

<body bgcolor="#ffffff">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
Image0 = new Image();
Image0.src = "xfile.php?xname=686QF01&fname=/images_bbs/lovely/165.gif";
Amount = 20;
Ymouse = -50;
Xmouse = -50;
Ypos = new Array();
Xpos = new Array();
Speed = new Array();
rate = new Array();
grow = new Array();
Step = new Array();
Cstep = new Array();
nsSize = new Array();
ns = (document.layers)?1:0;
(document.layers)?window.captureEvents(Event.MOUSEMOVE):0;
function Mouse(evnt) {
Ymouse=(document.layers)?evnt.pageY-20:event.y-20;
Xmouse=(document.layers)?evnt.pageX:event.x;
}
(document.layers)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
for (i = 0; i < Amount; i++) {
Ypos = Ymouse;
Xpos = Xmouse;
Speed = Math.random()*4+1;
Cstep = 0;
Step = Math.random()*0.1+0.05;
grow = 8;
nsSize = Math.random()*15+5;
rate = Math.random()*0.5+0.1;
}
if (ns) {
for (i = 0; i < Amount; i++) {
document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0><img src="+Image0.src+" name='N' width="+nsSize+" height="+nsSize+"></LAYER>");
}
}
else {
document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i = 0; i < Amount; i++) {
document.write('<img id="si" src="'+Image0.src+'" style="position:absolute;top:0px;left:0px;filter:alpha(opacity=90)">');
}
document.write('</div></div>');
}
function MouseBubbles() {
var hscrll = (document.layers)?window.pageYOffset:document.body.scrollTop;
var wscrll = (document.layers)?window.pageXOffset:document.body.scrollLeft;
for (i = 0; i < Amount; i++){
sy = Speed * Math.sin(270 * Math.PI / 180);
sx = Speed * Math.cos(Cstep * 4);
Ypos += sy;
Xpos += sx;
if (Ypos < -40) {
Ypos = Ymouse;
Xpos = Xmouse;
Speed = Math.random() * 6 + 4;
grow = 8;
nsSize = Math.random() * 15 + 5;
}
if (ns) {
document.layers['sn'+i].left = Xpos + wscrll;
document.layers['sn'+i].top = Ypos + hscrll;
}
else {
si.style.pixelLeft = Xpos + wscrll;
si.style.pixelTop = Ypos + hscrll;
si.style.width = grow;
si.style.height = grow;
}
grow += rate;
Cstep += Step;
if (grow > 24) grow = 25;
}
setTimeout('MouseBubbles()', 10);
}
MouseBubbles();
//  End -->
</script>
</body>
最后编辑2006-08-29 00:12:34.577000000