Js Based on the mouse movement speed, the method of automatically rotating the background image, js movement speed

Source: Internet
Author: User

Js Based on the mouse movement speed, the method of automatically rotating the background image, js movement speed

This article describes how js automatically rotates the background image based on the mouse movement speed. Share it with you for your reference. The specific implementation method is as follows:

Copy codeThe Code is as follows: <! 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> JavaScript allows you to quickly rotate images around the mouse </title>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312">
</Head>
<Body>
<Script language = "JavaScript">
<! --
Var images = '/favicon. ico ';
Var amount = 7;
Var speed = 1;
Var RunTime = 0;
Var cntr = 0;
Var xcntr = 100;
Var pulse = 25;
Var Xpos = 0;
Var Ypos = 0;
Var _ y;
Var temp;
/* If you use an image larger or smaller than the one I 've used
The cursor will be off center. Alter the 2 variables below to center it .*/
Var UpDown =-10;
Var LeftRight =-5;
If (document. all ){
Document. write ('<div id = "ieDiv" style = "position: absolute; top: 0px; left: 0px"> ');
Document. write ('<div id = "c" style = "position: relative"> ');
For (n = 0; n <amount; n ++)
Document. write (' ');
Document. write ('</div> ');
Document. write ('</div> ');
Function FollowMouse (){
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 );
Function xFollowMouse (evnt ){
Xpos = evnt. pageX + UpDown;
Ypos = evnt. pageY + LeftRight;
}
Window. onMouseMove = xFollowMouse;
For (ns = 0; ns <amount; ns ++)
Document. write ("<layer name = 'n'" + ns + "'left = '0' TOP = '0' VISIBILITY = 'hide '> </LAYER> ");
}
Function msi (){
If (document. layers ){
For (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 + = speed;
Stp = setTimeout ('msi () ', 10 );
If (cntr> = 100)
{
Cntr = 100;
Speed = 2.5;
For (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)
{
Speed = 0.5;
For (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 );
}
}
}
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 (RunTime + I * 4.5)/5 );
IeDiv. all. c. all [0]. style. left = Xpos + cntr * Math. sin (RunTime + I * 4.5)/5 );
}
Cntr + = 1;
RunTime + = speed;
Stp = setTimeout ('msi () ', 10 );
If (cntr> = 100)
{
Cntr = 100;
Speed = 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 (RunTime> 182)
{
Speed = 0.5;
For (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;
Else if (document. all)
_ Y =-document. body. clientWidth-90;
If (xcntr <= _ y)
{
RunTime = 0;
Speed = 1;
Cntr = 0;
Xcntr = 100;
}
}
Msi ()
// -->
</Script>
<Script language = "Javascript">
<! --
Function selectAll (theField ){
Var tempval = eval ("document." + theField)
Tempval. focus ()
Tempval. select ()
}
// -->
</Script>
</Body>
</Html>

I hope this article will help you design javascript programs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.