Skip to content

Instantly share code, notes, and snippets.

@Inndy
Forked from anonymous/index.html
Created April 22, 2016 16:25
Show Gist options
  • Save Inndy/1a8915082624a2d4bb191fda839513e5 to your computer and use it in GitHub Desktop.
Save Inndy/1a8915082624a2d4bb191fda839513e5 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/yacivicuga
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
#ball {
height: 6px;
width: 6px;
background-color: #00f;
border-radius: 100%;
position: absolute;
top: 120px;
left: 177px;
}
</style>
</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="">
<script id="jsbin-javascript">
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());
};
</script>
<script id="jsbin-source-css" type="text/css">#ball {
height: 6px;
width: 6px;
background-color: #00f;
border-radius: 100%;
position: absolute;
top: 120px;
left: 177px;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">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());
};</script></body>
</html>
#ball {
height: 6px;
width: 6px;
background-color: #00f;
border-radius: 100%;
position: absolute;
top: 120px;
left: 177px;
}
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());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment