Home > Web Front-end > JS Tutorial > body text

JavaScript spring oscillator super simple version fully complies with energy conservation and Hooke's theorem_javascript skills

WBOY
Release: 2016-05-16 18:43:30
Original
916 people have browsed it

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:

Copy the code The code is as follows:

< 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)


Copy code The code is as follows:
X-axis increment
Original amplitude multiple
Amplitude multiple attenuation number

Running time interval (milliseconds)

Please reactivate after stopping




This is a huge improvement over the last code! 100% original!
Repost
http://www.cnblogs.com/NONE/
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!