JAVA魔法師 -- 滑鼠跟屁蟲




學習主旨:可以隨你自行設定小小的圖檔,數量不限,讓這些圖檔跟著滑鼠跑來跑去.

完整程式:

<!-- ******************************************************
****** 當Div數字隨著圖檔的增加而逐個增加, ******
****** 每行指令後的 z-index:後的數字會逐個減少 ******
****** JAVA魔法師副手:龍包子 ******
****************************************************** -->
<div id="Div1" style="position:absolute; visibility:show; left:-50px; top:0px; z-index:5"><img src="sm01db1.gif"></div>
<div id="Div2" style="position:absolute; visibility:show; left:-50px; top:0px; z-index:4"><img src="sm01pb1.gif"></div>
<div id="Div3" style="position:absolute; visibility:show; left:-50px; top:0px; z-index:3"><img src="sm02or1.gif"></div>
<div id="Div4" style="position:absolute; visibility:show; left:-50px; top:0px; z-index:2"><img src="sm02p1.gif"></div>
<div id="Div5" style="position:absolute; visibility:show; left:-50px; top:0px; z-index:1"><img src="sm02r1.gif"></div>


<script language="javascript">
<!--
//Edit this part for the specs
//Length - MUST be >=0
var len=5;
//Update Speed - Lower = Faster
var speed=1;
//Distance Between Divs - Just play around w/ it.
var dist=3;
Images=new Array();



function init()
{Netscape = (navigator.appName.indexOf("Netscape")!=-1);
ImgPos=new Array();
ImgPos[0]=new Array();
ImgPos[1]=new Array();
DivName=new Array();
document.open();
for(i=0;i<len;i++)
{for(j=0;j<dist;j++)
{ImgPos[0][i*dist+j]=0;
ImgPos[1][i*dist+j]=0; }
DivName[i]="Div"+i;
}
document.close();
if(Netscape)
{document.captureEvents(Event.MOUSEMOVE);
document.onMouseMove = Moved; }
else
{document.onmousemove = MovedIE; }
Time=setTimeout('Slide()',speed);
}

function Slide()
{for(i=len*dist-1; i>0; i--)
{ImgPos[0][i]=eval(ImgPos[0][i-1]);
ImgPos[1][i]=eval(ImgPos[1][i-1]); }


for(i=1; i<len; i++)
{if(Netscape)
{document[DivName[i]].left=ImgPos[0][i*dist];
document[DivName[i]].top=ImgPos[1][i*dist]; }
else
{document.all(DivName[i]).style.left=ImgPos[0][i*dist];
document.all(DivName[i]).style.top=ImgPos[1][i*dist]; }
}
Time=setTimeout('Slide()',speed);
}

function Moved(e)
{ImgPos[0][0]=e.x+5;
ImgPos[1][0]=e.y+5; }

function MovedIE()
{ImgPos[0][0]=event.x+document.body.scrollLeft;
ImgPos[1][0]=event.y+document.body.scrollTop; }

init();
//-->
</script>


程式介紹: 龍包子