[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Diễn đàng » CÔNG NGHỆ THÔNG TIN » WEB » Tạo chuổi ngôi sao chạy theo chuột
Tạo chuổi ngôi sao chạy theo chuột
Duy_Khánhngày: Thứ Bảy, 2011-02-12, 9:48 AM | Message # 1
Thành viên cấp 10
nhóm: Administrators
Tin nhắn: 977
Danh tiếng: 6
Trạng thái: Offline
Code
<HTML>

<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 và 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="images/trailgif1.gif"height="10"width="10"border="0"name="trailSprite1img"></div><div id="trailSprite2"><img src="images/trailgif2.gif"height="10"width="10"border="0"name="trailSprite2img"></div><div id="trailSprite3"><img src="images/trailgif3.gif"height="10"width="10"border="0"name="trailSprite3img"></div><div id="trailSprite4"><img src="images/trailgif4.gif"height="10"width="10"border="0"name="trailSprite4img"></div><div id="trailSprite5"><img src="images/trailgif5.gif"height="10"width="10"border="0"name="trailSprite5img"></div><div id="trailSprite6"><img src="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.scrollLeft-0;");

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

}

}

function shuffleQueue()

{

lastItemPos = queue.length - 1;

lastItem = queue[lastItemPos];

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

queue[i] = 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>
 
Diễn đàng » CÔNG NGHỆ THÔNG TIN » WEB » Tạo chuổi ngôi sao chạy theo chuột
  • Page 1 of 1
  • 1
Search: