บทความนี้อธิบายวิธีการหมุนภาพพื้นหลังโดยอัตโนมัติตามความเร็วในการเคลื่อนที่ของเมาส์ แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title> JS ตระหนักถึงภาพที่จะหมุนอย่างรวดเร็วรอบ ๆ เมาส์ </title>
<meta http-equiv = "content-type" content = "text/html; charset = gb2312">>
</head>
<body>
<ภาษาสคริปต์ = "JavaScript">
-
ภาพ var = '/favicon.ico';
จำนวน var = 7;
ความเร็ว var = 1;
var runtime = 0;
var cntr = 0;
var xcntr = 100;
var pulse = 25;
var xpos = 0;
var ypos = 0;
ต่างกันไป;
var temp;
/*ถ้าคุณใช้ภาพที่ใหญ่กว่าหรือเล็กกว่าภาพที่ฉันเคยใช้
เคอร์เซอร์จะปิดอยู่ตรงกลางเติมค่าตัวแปร 2 ตัวด้านล่างไปยังจุดศูนย์กลาง*//
var updown = -10;
var leftright = -5;
if (document.all) {
document.write ('<div id = "iediv" style = "ตำแหน่ง: Absolute; Top: 0px; ซ้าย: 0px">');
document.write ('<div id = "c" style = "ตำแหน่ง: ญาติ">');
สำหรับ (n = 0; n <จำนวน; n ++)
document.write ('<img src = "'+images+'" style = "ตำแหน่ง: Absolute; top: 0px; ซ้าย: 0px; การมองเห็น: ซ่อน">');
document.write ('</div>');
document.write ('</div>');
ฟังก์ชั่น followmouse () {
xpos = document.body.scrollleft+event.x+updown;
ypos = document.body.scrolltop+event.y+leftright;
-
document.onmousemove = followmouse;
-
อื่นถ้า (document.layers) {
window.captureevents (event.mousemove);
ฟังก์ชั่น xfollowmouse (evnt) {
xpos = evnt.pagex+updown;
ypos = evnt.pagey+leftright;
-
window.onmousemove = xfollowmouse;
สำหรับ (ns = 0; ns <จำนวน; ns ++)
document.write ("<layer name = 'n"+ns+"' left = '0' top = '0' การมองเห็น = 'ซ่อน'> <img src = '"+ภาพ+"'> </layer>");
-
ฟังก์ชั่น msi () {
if (document.layers) {
สำหรับ (i = 0; i <ns; i ++)
-
temp = "n"+i
document.layers [0]. visibility = 'show';
document.layers [0] .top = ypos+cntr*math.cos ((รันไทม์+i*4.5)/5);
document.layers [0] .left = xpos+cntr*math.sin ((รันไทม์+i*4.5)/5);
-
cntr+= 1;
รันไทม์+= ความเร็ว;
stp = settimeout ('msi ()', 10);
ถ้า (cntr> = 100)
-
CNTR = 100;
ความเร็ว = 2.5;
สำหรับ (i = 0; i <ns; i ++)
-
temp = "n"+i
document.layers [temp] .visibility = 'show';
document.layers [temp] .top = ypos+cntr*math.cos ((runtime-100)*i/90);
document.layers [temp] .left = xpos+cntr*math.sin ((runtime-100)*i/90);
-
-
ถ้า (รันไทม์> 182)
-
ความเร็ว = 0.5;
สำหรับ (i = 0; i <ns; i ++)
-
temp = "n"+i
document.layers [temp] .top = ypos+xcntr*math.cos (((runtime-182)+i*4.5)/5);
document.layers [temp] .left = xpos+xcntr*math.sin (((runtime-182)+i*4.5)/5)*math.cos ((runtime-182)/5);
-
-
-
อื่นถ้า (document.all) {
สำหรับ (i = 0; i <iediv.all.c.all.length; i ++)
-
iediv.all.c.all [0] .style.visibility = 'มองเห็นได้';
iediv.all.c.all [0] .style.top = ypos+cntr*math.cos ((รันไทม์+i*4.5)/5);
iediv.all.c.all [0] .style.left = xpos+cntr*math.sin ((รันไทม์+i*4.5)/5);
-
cntr+= 1;
รันไทม์+= ความเร็ว;
stp = settimeout ('msi ()', 10);
ถ้า (cntr> = 100)
-
CNTR = 100;
ความเร็ว = 2.5;
สำหรับ (i = 0; i <iediv.all.c.all.length; i ++)
-
iediv.all.c.all [i] .style.visibility = 'มองเห็นได้';
iediv.all.c.all [i] .style.top = ypos+cntr*math.cos ((runtime-100)*i/90);
iediv.all.c.all [i] .style.left = xpos+cntr*math.sin ((runtime-100)*i/90);
-
-
ถ้า (รันไทม์> 182)
-
ความเร็ว = 0.5;
สำหรับ (i = 0; i <iediv.all.c.all.length; i ++)
-
iediv.all.c.all [i] .style.top = ypos+xcntr*math.cos (((runtime-182)+i*4.5)/5);
iediv.all.c.all [i] .style.left = xpos+xcntr*math.sin (((runtime-182)+i*4.5)/5)*math.cos ((runtime-182)/5);
-
-
-
ถ้า (รันไทม์> 210)
-
xcntr- = 10;
-
if (document.layers)
_y = -window.innerWidth-90;
อื่นถ้า (document.all)
_y = -document.body.clientWidth-90;
if (xcntr <= _y)
-
รันไทม์ = 0;
ความเร็ว = 1;
cntr = 0;
xcntr = 100;
-
-
MSI ()
-
</script>
<ภาษาสคริปต์ = "JavaScript">
-
ฟังก์ชั่น Selectall (Thefield) {
var tempval = eval ("เอกสาร"+thefield)
tempval.focus ()
tempval.select ()
-
-
</script>
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน