translateY
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 speed=5,
y=50,
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();
y+=speed;
//Bound the canvas area
if (y+speed > canvas.height-15 || y+speed <25) speed = -speed;
animation = requestAnimationFrame(draw);
}
canvas.addEventListener('mouseover', function() {
animation = requestAnimationFrame(draw);
});
canvas.addEventListener('mouseout', function() {
cancelAnimationFrame(animation);
});
</script>