JavaScript High simulation controllable spring oscillator realizes code _javascript skill

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> High Simulation spring oscillator (compressed use version) </title> <script type=" Text/javascript ">///////////// You can according to, the instructions in the teaching class to delete, modify a variety of elements for their own use (otherwise the teaching version is also OK, the variable name here is the teaching version of the variable names of each word of the first letter abbreviation, there is no change in the smoothness of the parameters, has been the most smooth). 2009/10/20 Lu Lianghan var hi=false; function IO () {Sl=parsefloat (document.getElementById ("SL"). Value) +2; if (SL <=1) {alert ("Speed loss >-1"); Return } T =parsefloat (document.getElementById ("T"). Value); if (T <0) {alert ("Big Brother!)" , I can't turn back the clock now "); Return } if (Hi==false) {hi=true; o= DOCUMENT.GEtelementbyid ("DIVM"); Si =parsefloat (document.getElementById ("SI"). Value); M (); } function Distance () {o= document.getElementById ("DIVM"); O.style.left=parsefloat (document.getElementById ("P"). Value) + "px"; function back () {if (HR) {Ts=false ; Hr=false; totm=0; im=0; O.style.left=parsefloat (document.getElementById ("P"). Value) + "px"; si=30; sl=3; Hi=false; } var TS = false; function S () {ts=true; }//////////////////////////////////////////////////////////////////////////////////this is Spring Begin////////// var o=0; var T =0 var si=30; var Hr=false; var sc=1; var im=true; var totm=0; var d= "R"; var Siadar = 1; var siadal = 1; var sl=3; function M () {if (TS) {hr=true; Return } if (HR) {return; } if (sc>0) {d= "R"; if (totm%2==0) {im=true;} else if (sc<0) {d= "L"; if (totm%2==1) {im=true;} } if (o.offsetleft<0&&totm==0) {o.style.left=o.offsetleft+si+ "px"; } if (totm==0) {sc=si; } if (totm!=0) {o.style.left=o.offsetleft+sc+ "px"; } if (O.offsetleft>=0&&totm%2==0&&im) {TOT m++; SC=SC-SL; Im=false; if (sc<=0) {hr=true; return;} else if (o.offsetleft>=0&&d== "R") {Sc=sc-siadar; else if (o.offsetleft>=0&&d== "L") {Sc=sc-siadal ; else if (O.offsetleft<=0&&totm%2==1&&im) {totm++; SC=SC+SL; Im=false; if (sc>=0) {hr=true; Return } else if (o.offsetleft<=0&&d== "L") { Sc=sc+siadar; else if (o.offsetleft<=0&&d== "R" &&totm!=0) {Sc=sc+sia DAL; } settimeout ("M ()", T); }///////////////////////////////////////////////////////////////here Spring is end////////// </script> </pe ad> <body> <div id= "Divmiddle" > <div id= "DIVM" onclick= "IO ()" > after setting up the new activation element and then point me!! </div> </div> <p> <input type= "button" value= "reactivate Element" id= "Back" onclick= "later"/> Run please activate & Lt;br> initial speed (in pixels per millisecond): <input type= "text" id= "SI" value= "/>" <br> move interval (in milliseconds): <input Type= "text" id= "T" value= "1"/> <br> half cycle loss (speed) energy (>-1): <input type= "text" id= "SL" value= "1"/> & Lt;br> distance (in pixels) from the start position to the middle axis: <input tYpe= "text" id= "P" value= "-1" onblur= "Distance ()"/> <br> <input type= "button" id= "Stop" value= "Stop Now" onclick = "Stop ()"/> </p> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Running here is my compressed version of the code (running some cards on the web), I will immediately, full version and annotated code upload (write very detailed, the first time in the blog to send code, it is very difficult to control!) Haha! And the masters are not laughed at, I use is a very stupid way, some days there will be a new special effects upload, (this spring is the page I do a button effect, I have a lot of special effects on the page, the page has not been finished, and so I finished all the original effects are sent up). Because I am still studying, the time that publishes new special effects may be very slow, please everybody understanding! (Everybody think some special effects style, give me some inspiration, haha!)

Programming Ideas:
The main use is physical thinking, imagine the process of spring movement, and then use if else and else if simulated, because the behavior of any thing is if. So.. So it can be done with if else!
Source: http://www.cnblogs.com/NONE/

Package download

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.