Share Chuỗi các ngôi sao bay theo Mouse

  • Thread starter Thread starter htnkenji
  • Start date Start date
H

htnkenji

New Member
Chú ý : Cần ảnh 6 ngôi sao , đặt nó trong 1 thư mục có tên là Images, bên ngoài thư mục đó là trang web có chứa đoạn mã bên dưới.

<?php
//--Code-->
<HEAD>

<
TITLE>Hieu u'ng JavaScript - Le Quang Anh Hu'ng</TITLE>

<
meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=x-user-defined">

<
META content="Microsoft FrontPage 4.0" name=GENERATOR>

<
META content="Le Quang Anh Hu'ng Homepage" name=Author>

<
script language=JavaScript>

<!--
Che dấu những trình duyệt mà không biết JavaScript (ở đây sử dụng câu lệnh If else if)

var
version = 0;

if (
navigator.userAgent.indexOf("MSIE 4") != -1) version = 5;

else if (
navigator.userAgent.indexOf("MSIE 3") != -1) version = 1;

else if (
navigator.userAgent.indexOf("Mozilla/4") != -1) version = 4;

else if (
navigator.userAgent.indexOf("Mozilla/4.5") != -1) version = 7;

else if (
navigator.userAgent.indexOf("Mozilla/3") != -1) version = 3;

else if (
navigator.userAgent.indexOf("Mozilla/2") != -1) version = 2;

else if (
navigator.userAgent.indexOf("MSIE 4.5") != -1) version = 6;

else
version = 8;

// -->

</SCRIPT>

<STYLE> <!-- Nơi đây dùng để tạo mẫu kích thước, vị trí cho Images(6 ngôi sao)--> #trailsprite1 {

HEIGHT: 10px; LEFT: 0px; POSITION: absolute; TOP: 1px; VISIBILITY: visible; WIDTH: 10px; Z-INDEX: 100

}

#trailsprite2 {

HEIGHT: 10px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 10px; Z-INDEX: 10

}

#trailsprite3 {

HEIGHT: 10px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 10px; Z-INDEX: 10

}

#trailsprite4 {

HEIGHT: 10px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 10px; Z-INDEX: 10

}

#trailsprite5 {

HEIGHT: 10px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 10px; Z-INDEX: 10

}

#trailsprite6 {

HEIGHT: 10px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 10px; Z-INDEX: 10

}

</STYLE>

</HEAD>

<BODY bgColor=#000000> <!-- chỉ màu nền background color -->

<script language=JavaScript1.1>

if (version > 3) <!-- Nếu ver > 3 (JavaScript) khi đó sẽ xuất ra màn hình bức ảnh thứ 1 và thứ tự tiếp theo ứng với mỗi images bao gồm chiều cao, viền, tên, Id -->

document.write('<div id="trailSprite1"><img src="http://www.vn-zoom.com/images/trailgif1.gif"height="10"width="10"border="0"name= "trailSprite1img"></div><div id="trailSprite2"><img src="http://www.vn-zoom.com/images/trailgif2.gif"height="10"width="10"border="0"name= "trailSprite2img"></div><div id="trailSprite3"><img src="http://www.vn-zoom.com/images/trailgif3.gif"height="10"width="10"border="0"name= "trailSprite3img"></div><div id="trailSprite4"><img src="http://www.vn-zoom.com/images/trailgif4.gif"height="10"width="10"border="0"name= "trailSprite4img"></div><div id="trailSprite5"><img src="http://www.vn-zoom.com/images/trailgif5.gif"height="10"width="10"border="0"name= "trailSprite5img"></div><div id="trailSprite6"><img src="http://www.vn-zoom.com/images/trailgif6.gif"height="10"width="10"border="0"name= "trailSprite6img"></div>')

</SCRIPT>

<script language=JavaScript> <!-- Nơi dòng lệnh này hỗ trợ cho trình duyệt Netscape không có cũng chẳng sao -->

<!--

NS4 = (("Netscape"==navigator.appName) && ("4"<=parseInt(navigator.appVersion)))

window.name = "right" <!-- Bạn phải cẩn thận ngay chổ chữ "right" đây là chỗ nguy hiểm chết người nếu bạn không để ý frames của bạn sẽ sổ tầm bậy liền đó, chính vì vậy bạn ấn định để sổ frames tên gì thì phải đặt tên đó à nghe! -->

// -->

</SCRIPT>

<script language=Javascript1.1>

<!--

var isNS = (navigator.appName == "Netscape");

layerRef = (isNS) ? "document" : "document.all";

styleRef = (isNS) ? "" : ".style";

var queue = new Array();var NUM_OF_TRAIL_PARTS = 6

for (x=1; x < 7; x++)

{ ///////////////Image Preload

eval("trailSpriteFrame" + x + "=new Image(10,10);");

eval("trailSpriteFrame" + x + ".src='images/trailgif"+x+".gif';");

}////////////////////////////////////////////////Đối tượng vệt ngôi sao chạy theo mouse

function trailSpriteObj(anID)

{

this.trailSpriteID = "trailSprite" + anID; //Tùy đằng trước

this.imgRef = "trailSprite" + anID + "img"; //Chuyển tới tên những ngôi sau

this.currentFrame = 1; //nhìn thấy khung

this.animateTrailSprite = animateTrailSprite; //Khai báo phương pháp vòng lặp đối tượng

}

function animateTrailSprite()

{

if (this.currentFrame <7)

{// Nếu có hoạt cảnh (mà) những khung rời bỏ, thay đổi những ngôi sao kết cấu hiện thời

if (isNS)

{ //Phát hiện ra bộ duyệt và thực hiện sự chuyển đổi hình ảnh

eval("document['"+this.imgRef+"'].src=trailSpriteFrame" + this.currentFrame + ".src");

}

else

{

eval("document['"+this.imgRef+"'].src=trailSpriteFrame" + this.currentFrame + ".src");

}

this.currentFrame ++; //và tăng thêm hiện thời những đối tượng hình ảnh

}

else

{ //Khung hiện hành như vậy đạt đến giới hạn nó che dấu ngôi sao

eval(layerRef + '.' + this.trailSpriteID + styleRef + '.visibility="hidden"');

}

}/////////////////////////////////////////////////////////////////

function processAnim()

{

for(x=0; x < NUM_OF_TRAIL_PARTS; x++)

queue[x].animateTrailSprite();

}

function processMouse(e)

{

currentObj = shuffleQueue();

if (isNS)

{

eval("document." + currentObj + ".left=e.pageX-0;");

eval("document." + currentObj + ".top=e.pageY+5;");

}

else

{

eval("document.all." + currentObj + ".style.pixelLeft=event.clientX+document.body.scro llLeft-0;");

eval("document.all." + currentObj + ".style.pixelTop=event.clientY+document.body.scrol lTop+5;");

}

}

function shuffleQueue()

{

lastItemPos = queue.length - 1;

lastItem = queue[lastItemPos];

for (i = lastItemPos; i>0; i--)

queue = queue[i-1];

queue[0] = lastItem;

queue[0].currentFrame = 1; //sự sắp đặt lại số thứ tự hình ảnh của những đối tượng & làm cho ngôi sao rõ ràng thêm

eval(layerRef + '.' + queue[0].trailSpriteID + styleRef + '.visibility="visible"');

return queue[0].trailSpriteID;

}

function init()

{

for(x=0; x<NUM_OF_TRAIL_PARTS; x++) //Sắp hàng đầy đủ vệt dài của đối tượng

queue[x] = new trailSpriteObj(x+1);

if (isNS)

{

document.captureEvents(Event.MOUSEMOVE);

}

document.onmousemove = processMouse;

setInterval("processAnim();",25);

}

if (version > 3)

window.onload = init;

// -->

</SCRIPT>

</body>

</html>
//--/Code-->
?>
Có hướng dẫn trong code rồi luôn đó. Chúc mọi người vui vẻ!
 
Cô bác đi qua,đi lại bấm nút thank giúp cháu để cháu có host làm forum đi.
 

Facebook Comments

Similar threads

Admin
Replies
0
Views
951
AdminAdmin is verified member.
Admin
Admin
Replies
1
Views
3K
onizuka
O
Back
Top