lmgonzalves / segment

A JavaScript library to draw and animate SVG path strokes
http://lmgonzalves.github.io/segment
MIT License
1.74k stars 98 forks source link

Add Stop animation in object #12

Closed driedel-zz closed 8 years ago

driedel-zz commented 8 years ago

I'm using segment to make a countdown, and if I skip the item before the animation end it still counting. If I come back to the item and try to start from zero the plugin ignores because the animationTimer still running.

I put the stop function visible to the object and use it to reset the counter... works perfectly :)

lmgonzalves commented 8 years ago

Hi, thanks for contributing! Please help me understand this, because stop function is actually public. So, you don't need:

this.stop = this.stop;

But seems a good idea to call stop in the constructor instead setting timer and animationTimer to null. Something like:

this.draw(this.begin, this.end, 0, {circular: this.circular});
this.stop();
driedel-zz commented 8 years ago

Hi :)

I'm sorry, I suggest something that already works :(

I was trying to stop just setting the .draw to zero, but it doesn't stop the animation... so I look at your code the stop function and don't try to call it because it was not listed in the constructor..

I've made an example in JSFiddle, and it works perfectly.

https://fiddle.jshell.net/driedel/fcmy8dq9/

Look at the updateTimer function and you will understand my mistake.

lmgonzalves commented 8 years ago

mmm, I see. Ok, I will document stop function in README as soon as possible :) Thanks!