Artikel ini menjelaskan metode memutar secara otomatis gambar latar belakang berdasarkan kecepatan gerakan mouse. Bagikan untuk referensi Anda. Metode implementasi spesifik adalah sebagai berikut:
Salin kode sebagai berikut: <! Doctype html public "-// w3c // dtd xhtml 1.0 transisi // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<Title> JS menyadari gambar untuk berputar dengan cepat di sekitar mouse </iteme>
<meta http-equiv = "konten tipe" content = "text/html; charset = gb2312">
</head>
<body>
<bahasa skrip = "javascript">
<!-
var gambar = '/favicon.ico';
jumlah var = 7;
var speed = 1;
var runtime = 0;
var cntr = 0;
var xcntr = 100;
var pulsa = 25;
var xpos = 0;
var ypos = 0;
bervariasi;
var temp;
/*Jika Anda menggunakan gambar yang lebih besar atau lebih kecil dari yang saya gunakan
Kursor akan berada di tengah.
var updown = -10;
var LefTright = -5;
if (document.all) {
document.write ('<div id = "iediv" style = "Posisi: absolute; atas: 0px; kiri: 0px">');
document.write ('<div id = "c" style = "position: relatif">');
untuk (n = 0; n <jumlah; n ++)
document.write ('<img src = "'+gambar+'" style = "posisi: absolute; atas: 0px; kiri: 0px; visibilitas: tersembunyi">');
document.write ('</div>');
document.write ('</div>');
fungsi followmouse () {
Xpos = document.body.scrollleft+event.x+updown;
Ypos = document.body.scrolltop+event.y+leftright;
}
document.onmouseMove = followmouse;
}
lain if (document.layers) {
window.captureEvents (event.mouseMove);
fungsi xfollowmouse (evnt) {
Xpos = evnt.pagex+updown;
Ypos = evnt.pagey+leftright;
}
window.onmouseMove = xfollowmouse;
untuk (ns = 0; ns <jumlah; ns ++)
Document.write ("<Lapisan Nama = 'n"+ns+"' Left = '0' Top = '0' Visibilitas = 'Sembunyikan'> <img src = '"+gambar+"'> </layer>");
}
fungsi msi () {
if (document.layers) {
untuk (i = 0; i <ns; i ++)
{
temp = "n"+i
document.layers [0] .visibility = 'show';
document.layers [0] .top = ypos+cntr*math.cos ((runtime+i*4.5)/5);
Document.layers [0] .LEFT = XPOS+CNTR*MATH.SIN ((Runtime+I*4.5)/5);
}
CNTR+= 1;
Runtime+= kecepatan;
stp = setTimeout ('msi ()', 10);
if (cntr> = 100)
{
cntr = 100;
Kecepatan = 2.5;
untuk (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);
}
}
if (runtime> 182)
{
Kecepatan = 0,5;
untuk (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);
}
}
}
lain jika (document.all) {
untuk (i = 0; i <iediv.all.c.all.length; i ++)
{
iediv.all.c.all [0] .style.visibility = 'visible';
iediv.all.c.all [0] .style.top = ypos+cntr*math.cos ((runtime+i*4.5)/5);
iediv.all.c.all [0] .style.left = xpos+cntr*math.sin ((runtime+i*4.5)/5);
}
CNTR+= 1;
Runtime+= kecepatan;
stp = setTimeout ('msi ()', 10);
if (cntr> = 100)
{
cntr = 100;
Kecepatan = 2.5;
untuk (i = 0; i <iediv.all.c.all.length; i ++)
{
iediv.all.c.all [i] .style.visibility = 'visible';
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);
}
}
if (runtime> 182)
{
Kecepatan = 0,5;
untuk (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);
}
}
}
if (runtime> 210)
{
xcntr- = 10;
}
if (document.layers)
_y = -window.innerwidth-90;
lain jika (document.all)
_y = -document.body.clientwidth-90;
if (xcntr <= _y)
{
Runtime = 0;
Kecepatan = 1;
cntr = 0;
xcntr = 100;
}
}
MSI ()
//->
</script>
<bahasa skrip = "javascript">
<!-
function selectAll (theField) {
var tempval = eval ("dokumen."+theField)
tempval.focus ()
tempval.select ()
}
//->
</script>
</body>
</html>
Saya harap artikel ini akan membantu pemrograman JavaScript semua orang.