Fully in line with conservation of energy, the Javascript spring vibrator of the Hulk theorem (ultra-simplified version, beyond the first version !)

Source: Internet
Author: User
X axis Increment
Original amplitude multiple
Amplitude multiple attenuation count
Running interval (MS)
Activate the service again after it is stopped.
Activate it again after running! Click me after setting!

The last version uses physical thoughts. This time, it uses mathematical ideas. If you have downloaded the first versionCodeYou can clearly feel the power of mathematics !!!!! QQ: 50352735
Here is the JS Code of spring:

Code
< Script Type = " Text/JavaScript " >
// /// // This spring begin /////////////////////
VaR X = 0.1 // X axis Increment
VaR T = 0 ; // Initial Position on the X axis
VaR M = 200 ; // Original amplitude multiple
VaR A = 0.7 ; // Amplitude multiple attenuation count
VaR D = ' R ' ; // MOVEMENT DIRECTION
VaR O = 0 ; // Element
VaR L = 0 ; // Location
VaR Ti = 30 ;
VaR S = False ;
VaR HR = False ;

Function R (){
HR = True ;
If (S)
{
Return ;
}
O. style. Left = L + (Math. Sin (t )) * M + " Px " ; // Get spring motion speed
T = T + X; // X axis Growth
M -= A; // Unit time attenuation
If (M <= 0 ) // Zero Amplitude
{
S = True ;
Return ; // Exit
}
SetTimeout ( " R () " , Ti ); // Callback
}
// //// // This spring over //////////////////// ///////
Function I ()
{
If (HR ){
Return ;
}
S = False ;
O = Document. getelementbyid ( " Div " );
X = Parsefloat (document. getelementbyid ( " X " ). Value );
M = Parsefloat (document. getelementbyid ( " M " ). Value );
A = Parsefloat (document. getelementbyid ( " A " ). Value );
Ti = Parsefloat (document. getelementbyid ( " Ti " ). Value );
L = Document. getelementbyid ( " Div " ). Offsetleft;
R ();
}
Function TS ()
{
S = True ;
}
Function B ()
{
If (S)
{
T = 0
HR = False ;
S = False ;
X = Parsefloat (document. getelementbyid ( " X " ). Value );
M = Parsefloat (document. getelementbyid ( " M " ). Value );
A = Parsefloat (document. getelementbyid ( " A " ). Value );
Document. getelementbyid ( " Div " ). Style. Left = L + " Px " ;
}
}

</SCRIPT>

Here is the HTML in the webpage (useless, for demonstration)Htmlcode
< Div ID = "P" Style = "Width: 500px; Height: 400px ;" >
< Input Style = "Width: 50px" Type = "Text" ID = "X" Value = "0.1"   /> X axis Increment < BR /> < Input Style = "Width: 50px" Type = "Text" ID = "M" Value = "200"   /> Original amplitude multiple < BR />
< Input Style = "Width: 50px" Type = "Text" ID = "" Value = "0.7"   /> Amplitude multiple attenuation count < BR />
< Input Style = "Width: 50px" Type = "Text" ID = "Ti" Value = "30"   /> Running interval (MS) < BR />
< Input Style = "Width: 80px" Type = "Button" Onclick = "Ts ()" Value = "Stop" /> Activate the service again after it is stopped. < BR /> < Input Style = "Width: 80px" Type = "Button" Onclick = "B ()" Value = "Reactivate" />
</ Div > < Div Style = "Position: absolute ;" > < Div ID = "Div" Onclick = "I ()" Value = "Click me after setting! " Style = "Position: absolute; top:-pixel PX; left: 211px; width: 50px; Height: 50px; Background-color: # ff0 ;" > </ Div > </ Div >

This is better than the previous code! 100% original! Therefore, for reprint, please describe the source:
Http://www.cnblogs.com/NONE/archive/2009/10/25/JavaScriptTrueBornSpring.html

Related Article

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.