이 기사에서는 마우스 이동 속도에 따라 배경 이미지를 자동으로 회전시키는 방법에 대해 설명합니다. 참조를 위해 공유하십시오. 특정 구현 방법은 다음과 같습니다.
코드를 다음과 같이 복사하십시오.
<html xmlns = "http://www.w3.org/1999/xhtml">
<헤드>
<title> js는 마우스 주변에서 빠르게 회전하는 이미지를 인식합니다 </title>
<meta http-equiv = "content-type"content = "text/html; charset = gb2312">
</head>
<body>
<script language = "javaScript">
<!-
var images = '/favicon.ico';
van 금액 = 7;
var 속도 = 1;
var 런타임 = 0;
var cntr = 0;
var xcntr = 100;
var 펄스 = 25;
var xpos = 0;
var ypos = 0;
달라지다;
var 온도;
/*내가 사용한 것보다 크거나 작은 이미지를 사용하는 경우
커서는 중앙에서 벗어납니다.
var updown = -10;
var leftright = -5;
if (document.all) {
document.write ( '<div id = "iediv"style = "위치 : 절대; 상단 : 0px; 왼쪽 : 0px">');
document.write ( '<div id = "c"style = "위치 : 상대">');
for (n = 0; n <양; n ++)
documb
document.write ( '</div>');
document.write ( '</div>');
함수 follow mouse () {
XPOS = document.body.scrollleft+event.x+updown;
ypos = document.body.scrolltop+event.y+leftright;
}
document.onmouseMove = followMouse;
}
else if (document.layers) {
window.captureEvents (event.mouseMove);
함수 XFOLLOWMOUSE (EVNT) {
xpos = evnt.pagex+updown;
ypos = evnt.pagey+leftright;
}
Window.onmouseMove = XfollowMouse;
for (ns = 0; ns <fold; ns ++)
document.write ( "<layer name = 'n"+ns+"'left = '0'top = '0'가시성 = 'hide'> <img src = '"+images+"'> </layer>");
}
함수 msi () {
if (document.layers) {
for (i = 0; i <ns; i ++)
{
온도 = "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);
if (cntr> = 100)
{
CNTR = 100;
속도 = 2.5;
for (i = 0; i <ns; i ++)
{
온도 = "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 (런타임> 182)
{
속도 = 0.5;
for (i = 0; i <ns; i ++)
{
온도 = "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);
}
}
}
else if (document.all) {
for (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 ((런타임+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);
if (cntr> = 100)
{
CNTR = 100;
속도 = 2.5;
for (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 (런타임> 182)
{
속도 = 0.5;
for (i = 0; i <iediv.all.c.all.length; i ++)
{
iediv.all.c.all [i] .style.top = ypos+xcntr*math.cos (((런타임 -182)+i*4.5)/5);
IEDIV.ALL.C.ALL [i] .style.left = XPOS+XCNTR*MATH.SIN (((Runtime-182)+I*4.5)/5)*Math.Cos ((런타임 -182)/5);
}
}
}
if (런타임> 210)
{
xcntr- = 10;
}
if (document.layers)
_y = -window.innerwidth-90;
else if (document.all)
_y = -document.body.clientWidth-90;
if (xcntr <= _y)
{
런타임 = 0;
속도 = 1;
cntr = 0;
xcntr = 100;
}
}
msi ()
//->
</스크립트>
<script language = "javaScript">
<!-
함수 selectall (Thefield) {
var tempval = eval ( "문서"+Thefield)
tempval.focus ()
tempval.select ()
}
//->
</스크립트>
</body>
</html>
이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.