index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. I loved Virgil's Dribble shot and decided to remake
  3. it with some SVG animations :) I didn't really want
  4. to recreate the curvy line since I believe straight
  5. lines are more accurate. Sorry Virgil, I might make
  6. them curvy one day :)! With a bit of time on my
  7. hands I could make it even more detailed.
  8. I hope you like it and post some feedback on how to
  9. make this better :)!
  10. Don't forget to check out the original at
  11. http://goo.gl/0aKiS0
  12. Kudos Virgil!*/
  13. function drawCircle(container,id,progress,parent){
  14. var paper = Snap(container);
  15. var prog = paper.path("M5,50 A45,45,0 1 1 95,50 A45,45,0 1 1 5,50");
  16. var lineL = prog.getTotalLength();
  17. var oneUnit = lineL/100;
  18. var toOffset = lineL - oneUnit * progress;
  19. var myID = 'circle-graph-'+id;
  20. prog.attr({
  21. 'stroke-dashoffset':lineL,
  22. 'stroke-dasharray':lineL,
  23. 'id':myID
  24. });
  25. var animTime = 1300/*progress / 100*/
  26. prog.animate({
  27. 'stroke-dashoffset':toOffset
  28. },animTime,mina.easein);
  29. function countCircle(animtime,parent,progress){
  30. var textContainer = $(parent).find('.circle-percentage');
  31. var i = 0;
  32. var time = 1300;
  33. var intervalTime = Math.abs(time / progress);
  34. var timerID = setInterval(function () {
  35. i++;
  36. textContainer.text(i+"%");
  37. if (i === progress) clearInterval(timerID);
  38. }, intervalTime);
  39. }
  40. countCircle(animTime,parent,progress);
  41. }
  42. drawCircle('#chart-3',1,77,'#circle-1');
  43. drawCircle('#chart-4',2,53,'#circle-2');