紫龍
|
分享:
▼
x0
|
[JScript][教學] [範例]網頁特效
在網頁增加美美的特效
<SCRIPT language=JavaScript> <!-- var number =12 var speed = 50 var maximg =2 var act = new Array(),positionX = new Array(),positionY = new Array() var moveX = new Array(),moveY = new Array() var j = maximg img = new Array() img[0] = "1.gif" img[1] = "2.gif" img[2] = "3.gif" for (var i = 0; i < number ;++ i) { act = 0 positionX = Math.random()*document.body.clientWidth-50 positionY = Math.random()*document.body.clientHeight moveX = 0.1 + Math.random()/100 moveY = 0.1 + Math.random()*3 if (i == 0) { document.write("<div id=\"fly"+ i +"\" style=\"POSITION] + "\" border=\"0\"></div>")} else { document.write("<div id=\"fly"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible\"><img src=\"" + img[j] + "\" border=\"0\"></div>")} if (j == 0) { j = maximg } else { j -= 1 } } function gofly() { for (var i = 0; i < number ;++ i) { // iterate for every fly positionY -= moveY act += moveX document.all["fly"+i].style.pixelTop = positionY+ Math.cos(act)*positionY/15 document.all["fly"+i].style.pixelLeft = positionX + Math.sin(act)*positionX/50 if (positionY < 0) { moveX = 0.1+ Math.random()/100 moveY = 0.1 + Math.random()*3 positionX = Math.random()*document.body.clientWidth-50 positionY = document.body.clientHeight } } setTimeout("gofly()", speed) } gofly() --> </SCRIPT>
在 var number =12 中修改圖片出現的數量 在 var speed = 50 中修改變換的速度 在 var maximg =2 中修改圖片的數量(真實數量-1) 自行修改圖片的名稱或路徑
[ 此文章被codeboy在2004-12-11 01:02重新編輯 ]
|