not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.8 KiB

  1. define (function() {
  2. function Progress(size, color, progress, target) {
  3. this.size = size
  4. this.color = color
  5. this.progress = progress
  6. this.target = target
  7. this.draw = function() {
  8. target.innerHTML = '<canvas id="progressCircle"></canvas>'
  9. var canvasCSS =
  10. '#progressCircle {\
  11. position: absolute;\
  12. transform: rotate(-90deg) rotateX(180deg);\
  13. top: 0px;\
  14. left: 0px;\
  15. } '
  16. var styleSheet = window.document.styleSheets[0]
  17. styleSheet.insertRule(canvasCSS, styleSheet.cssRules.length)
  18. this.canvas = document.getElementById('progressCircle')
  19. this.canvas.width = this.size
  20. this.canvas.height = this.size
  21. this.ctx = this.canvas.getContext('2d')
  22. this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight)
  23. this.ctx.beginPath()
  24. this.ctx.arc(
  25. this.canvas.width / 2,
  26. this.canvas.height / 2,
  27. this.size / 4,
  28. 0,
  29. Math.PI*2*this.progress,
  30. false
  31. )
  32. this.ctx.lineWidth = this.size / 2
  33. this.ctx.strokeStyle = this.color
  34. this.ctx.stroke()
  35. }
  36. this.update = function(progress) {
  37. this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight)
  38. this.ctx.beginPath()
  39. this.ctx.arc(
  40. this.canvas.width / 2,
  41. this.canvas.height / 2,
  42. this.size / 4,
  43. 0,
  44. Math.PI*2*progress,
  45. false
  46. )
  47. this.ctx.lineWidth = this.size / 2
  48. this.ctx.strokeStyle = this.color
  49. this.ctx.stroke()
  50. }
  51. this.handleResize = function(size, progress) {
  52. this.canvas.width = size
  53. this.canvas.height = size
  54. this.update()
  55. }
  56. this.updateColor = function(color, progress) {
  57. this.color = color
  58. this.update(progress)
  59. }
  60. }
  61. return Progress
  62. })