The last edition uses the physics thought, this time uses the mathematics thought, if you have downloaded the first edition the code can obviously feel the mathematics powerful!!!!!
Here is the spring of the JS code:
Copy Code code as follows:
<script type= "Text/javascript" >
This spring begin/////////////////////
var x=0.1//x axis Increment
var t=0;//x axis initial position
var m=200; Original amplitude multiple
The attenuation number of amplitude multiples of Var a=0.7;//
var d= ' R '//direction of motion
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 Decay
if (m<=0)//amplitude is zero
{
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 page (no use, for demo)
Copy Code code as follows:
<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="/> Original amplitude multiples <br/>
<input style= "width:50px" type= "text" id= "A" value= "0.7"/> Amplitude multiplier attenuation <br/>
<input style= "width:50px" type= "text" id= "TI" value= "/>" Run time interval (ms) <br/>
<input style= "width:80px" type= "button" onclick= "TS ()" value= "Stop"/> Please activate <br/><input style= "width : 80px "type=" button "onclick=" B () "value=" New activation/>
</div><div style= "Position:absolute;" ><div id= "div" onclick= "I ()" Value= settings after setting point me! "style=" Position:absolute; top:-264px; left:211px; width:50px; height:50px; Background-color: #FF0; " ></div></div>
This is much better than the last code! 100% Original!
Reprint http://www.cnblogs.com/NONE/