The previous version used physical thinking, this time it uses mathematical thinking. If you have downloaded the code of the first version, you can clearly feel the power of mathematics! ! ! ! !
Here is the JS code of spring:
< script type="text/javascript">
//////////////////this spring begin////////////////// ////
var X=0.1//X-axis increment
var T=0;//Initial position of 0.7;//Amplitude multiple attenuation number
var D='R';//Motion direction
var O=0;//Element
var L=0;//Position
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 the spring movement speed
T=T X;//X-axis growth
M-=A;//Unit time decay
if(M<=0)//The 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 (documen.getelementByid (" a "). Value); Then, then getElementById("div").style.left=L "px";
}
}
This is the page HTML (useless, just for demonstration)
http://www.cnblogs.com/NONE/
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn