Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
- </head>
- <body style="margin:0">
- <div id="test" style="width:100px; height:100px; background:red"></div>
- <script>
- var
- uv = 0, // final velocity
- d = 400, // distance
- a = -2, // acceleration
- iv = Math.sqrt( -2 * a * d ), // initialVelocity = sqrt( -2 * acceleration * distance );
- cv = iv, // current velocity
- p = 0, // position
- f = function(){
- var av = cv + (a / 2); // average velocity
- p += av;
- cv += a;
- $('#test').css('margin-left', Math.round(p) );
- console.log(cv,p-d,$('#test').css('margin-left'));
- if(Math.abs(p-d)<.1) return clearInterval(loop);
- };
- loop = setInterval(f,30);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement