Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div id="ball"></div>
  
  <button id="pause">Pause / Run</button>
  <button id="reset">Reset</button>
  
  <img src="https://media.giphy.com/media/3o7WTN8FmMgK9hrZyU/giphy.gif" alt="">
</body>
</html>
 
var pos = 0;
var MAX = 100;
var freq = 53;
var dist = 280;
var running = false;
function move(force)
{
  if(!force && !running) return pos;
  pos = (pos + 1) % MAX;
  console.log('move');
  
  var rate = pos / MAX;
  
  var theta = Math.PI * 2 * rate;
  
  var x = dist / 2 * (1 + Math.sin(theta));
  
  ball.style.top = (x + 60) + 'px';
  
  return pos;
}
setInterval(move, 1000 / freq);
pause.onclick = function () {
  running = !running;
};
reset.onclick = function () {
  pos = 969;
  console.log(move());
};
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers