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