GravityFall
MouseOver on canvas above
Code
<canvas id="canvas" width="200" height="200" style="background-color: #f9f9f9;cursor:pointer;"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var y=50,
speed=1,
gravity=0.08,
animation;
function draw() {
ctx.clearRect(0,0, canvas.width, canvas.height);
ctx.beginPath();
ctx.arc(100, y, 15, 0, Math.PI * 2, true);
ctx.stroke();
speed+=gravity;
y+=speed;
//To stop the ball on ground
if (y> canvas.height-15) y = canvas.height-15;
animation = requestAnimationFrame(draw);
}
canvas.addEventListener('mouseover', function() {
animation = requestAnimationFrame(draw);
});
canvas.addEventListener('mouseout', function() {
cancelAnimationFrame(animation);
});
</script>