Requires

Provides

Contains the basic animation logic to be extended by all other Fx Classes.

License:
MIT-style license.
  1. 18
  2. 19
  3. 20
  4. 21
  5. 22
  6. 23
  7. 24
(function(){ var Fx = this.Fx = new Class({ Implements: [Chain, Events, Options], options: {

onStart: nil, onCancel: nil, onComplete: nil,

  1. 30
  2. 31
  3. 32
  4. 33
  5. 34
  6. 35
  7. 36
  8. 37
  9. 38
  10. 39
  11. 40
  12. 41
  13. 42
  14. 43
  15. 44
  16. 45
  17. 46
  18. 47
  19. 48
  20. 49
  21. 50
  22. 51
  23. 52
  24. 53
  25. 54
  26. 55
  27. 56
  28. 57
  29. 58
  30. 59
  31. 60
  32. 61
  33. 62
  34. 63
  35. 64
  36. 65
  37. 66
  38. 67
  39. 68
  40. 69
  41. 70
  42. 71
  43. 72
  44. 73
  45. 74
  46. 75
  47. 76
  48. 77
  49. 78
  50. 79
  51. 80
  52. 81
  53. 82
  54. 83
  55. 84
  56. 85
  57. 86
  58. 87
  59. 88
  60. 89
  61. 90
  62. 91
  63. 92
  64. 93
  65. 94
  66. 95
  67. 96
  68. 97
  69. 98
  70. 99
  71. 100
  72. 101
  73. 102
  74. 103
  75. 104
  76. 105
  77. 106
  78. 107
  79. 108
  80. 109
  81. 110
  82. 111
  83. 112
  84. 113
  85. 114
  86. 115
  87. 116
  88. 117
  89. 118
  90. 119
  91. 120
  92. 121
  93. 122
  94. 123
  95. 124
  96. 125
  97. 126
  98. 127
  99. 128
  100. 129
  101. 130
  102. 131
  103. 132
  104. 133
  105. 134
  106. 135
  107. 136
  108. 137
  109. 138
  110. 139
  111. 140
  112. 141
  113. 142
  114. 143
  115. 144
  116. 145
  117. 146
  118. 147
  119. 148
  120. 149
fps: 60, unit: false, duration: 500, frames: null, frameSkip: true, link: 'ignore' }, initialize: function(options){ this.subject = this.subject || this; this.setOptions(options); }, getTransition: function(){ return function(p){ return -(Math.cos(Math.PI * p) - 1) / 2; }; }, step: function(now){ if (this.options.frameSkip){ var diff = (this.time != null) ? (now - this.time) : 0, frames = diff / this.frameInterval; this.time = now; this.frame += frames; } else { this.frame++; } if (this.frame < this.frames){ var delta = this.transition(this.frame / this.frames); this.set(this.compute(this.from, this.to, delta)); } else { this.frame = this.frames; this.set(this.compute(this.from, this.to, 1)); this.stop(); } }, set: function(now){ return now; }, compute: function(from, to, delta){ return Fx.compute(from, to, delta); }, check: function(){ if (!this.isRunning()) return true; switch (this.options.link){ case 'cancel': this.cancel(); return true; case 'chain': this.chain(this.caller.pass(arguments, this)); return false; } return false; }, start: function(from, to){ if (!this.check(from, to)) return this; this.from = from; this.to = to; this.frame = (this.options.frameSkip) ? 0 : -1; this.time = null; this.transition = this.getTransition(); var frames = this.options.frames, fps = this.options.fps, duration = this.options.duration; this.duration = Fx.Durations[duration] || duration.toInt(); this.frameInterval = 1000 / fps; this.frames = frames || Math.round(this.duration / this.frameInterval); this.fireEvent('start', this.subject); pushInstance.call(this, fps); return this; }, stop: function(){ if (this.isRunning()){ this.time = null; pullInstance.call(this, this.options.fps); if (this.frames == this.frame){ this.fireEvent('complete', this.subject); if (!this.callChain()) this.fireEvent('chainComplete', this.subject); } else { this.fireEvent('stop', this.subject); } } return this; }, cancel: function(){ if (this.isRunning()){ this.time = null; pullInstance.call(this, this.options.fps); this.frame = this.frames; this.fireEvent('cancel', this.subject).clearChain(); } return this; }, pause: function(){ if (this.isRunning()){ this.time = null; pullInstance.call(this, this.options.fps); } return this; }, resume: function(){ if ((this.frame < this.frames) && !this.isRunning()) pushInstance.call(this, this.options.fps); return this; }, isRunning: function(){ var list = instances[this.options.fps]; return list && list.contains(this); } }); Fx.compute = function(from, to, delta){ return (to - from) * delta + from; }; Fx.Durations = {'short': 250, 'normal': 500, 'long': 1000};

global timers

  1. 153
  2. 154
  3. 155
  4. 156
  5. 157
  6. 158
  7. 159
  8. 160
  9. 161
  10. 162
  11. 163
  12. 164
  13. 165
  14. 166
  15. 167
  16. 168
  17. 169
  18. 170
  19. 171
  20. 172
  21. 173
  22. 174
  23. 175
  24. 176
  25. 177
  26. 178
  27. 179
  28. 180
var instances = {}, timers = {}; var loop = function(){ var now = Date.now(); for (var i = this.length; i--;){ var instance = this[i]; if (instance) instance.step(now); } }; var pushInstance = function(fps){ var list = instances[fps] || (instances[fps] = []); list.push(this); if (!timers[fps]) timers[fps] = loop.periodical(Math.round(1000 / fps), list); }; var pullInstance = function(fps){ var list = instances[fps]; if (list){ list.erase(this); if (!list.length && timers[fps]){ delete instances[fps]; timers[fps] = clearInterval(timers[fps]); } } }; })();