Stop animation with requestAnimationFrame on canvas

2

I'm using Canvas to do this link , but I'd like to stop the animation by clicking on div using some requestAnimationFrame functionality. I used setInterval but the animation does not look cool, so I decided to use requestAnimationFrame but I can not stop the animation after a click and continue after another click.

The code works simply with a circle above a line using the clip() method, and when you click the div , the circle moves on the x-axis by going over the line showing it, only I want to stop the animation after a click and then continue (like a play and stop button, giving the intention that the line has stopped growing).

Would it also be possible for me to define a path for the circumference to follow after the click? Example: link

* In my example it follows a path, but it is straight, I wanted the circumference moves by a path already pre-defined as in the above example.

    
asked by anonymous 28.07.2015 / 19:29

1 answer

0

I managed, what I did was simply put:

ctx.clearRect(cx, 0, canvas.width, canvas.heigth) 

With cx moving left or right, then it seemed that the line was increasing or decreasing!

    
28.07.2015 / 22:33