@@ -20,9 +20,9 @@ snabbtjs.Animation.prototype.assign = function(options) {
20
20
21
21
this . start_time = 0 ;
22
22
this . current_time = 0 ;
23
+ this . _stopped = false ;
23
24
// Manual related, should probably be subclassed
24
25
this . value = 0 ;
25
- this . cancelled = false ;
26
26
27
27
if ( this . mode === snabbtjs . AnimationType . SPRING ) {
28
28
options . equilibrium_position = 1 ;
@@ -40,8 +40,19 @@ snabbtjs.Animation.prototype.assign = function(options) {
40
40
}
41
41
} ;
42
42
43
+ snabbtjs . Animation . prototype . stop = function ( ) {
44
+ this . _stopped = true ;
45
+ } ;
46
+
47
+ snabbtjs . Animation . prototype . stopped = function ( ) {
48
+ return this . _stopped ;
49
+ } ;
50
+
43
51
snabbtjs . Animation . prototype . tick = function ( time ) {
44
52
// If first tick, set start_time
53
+ if ( this . _stopped )
54
+ return ;
55
+
45
56
if ( ! this . start_time ) {
46
57
this . start_time = time ;
47
58
}
@@ -71,11 +82,14 @@ snabbtjs.Animation.prototype.set_value = function(value) {
71
82
} ;
72
83
73
84
snabbtjs . Animation . prototype . current_state = function ( ) {
74
- this . update_current_transition ( ) ;
85
+ if ( ! this . _stopped )
86
+ this . update_current_transition ( ) ;
75
87
return this . _current_state ;
76
88
} ;
77
89
78
90
snabbtjs . Animation . prototype . completed = function ( ) {
91
+ if ( this . _stopped )
92
+ return true ;
79
93
if ( this . mode == snabbtjs . AnimationType . TIME ) {
80
94
if ( this . start_time === 0 ) {
81
95
return false ;
@@ -93,6 +107,9 @@ snabbtjs.Animation.prototype.start_state = function() {
93
107
} ;
94
108
95
109
snabbtjs . Animation . prototype . end_state = function ( ) {
110
+ if ( this . _stopped )
111
+ return this . current_state ( ) ;
112
+
96
113
if ( this . mode == snabbtjs . AnimationType . TIME || this . mode == snabbtjs . AnimationType . SPRING ) {
97
114
return this . _end_state ;
98
115
} else {
@@ -196,17 +213,28 @@ snabbtjs.ScrollAnimation.prototype.completed = function() {
196
213
} ;
197
214
198
215
// ------------------------
199
- // -- AttantionAnimation --
216
+ // -- AttentionAnimation --
200
217
// ------------------------
201
218
202
219
snabbtjs . AttentionAnimation = function ( options ) {
203
220
this . movement = options . movement ;
204
221
this . current_movement = new snabbtjs . State ( { } ) ;
205
222
options . initial_velocity = 0.1 ;
206
223
this . spring = new snabbtjs . SpringEasing ( options ) ;
224
+ this . _stopped = false ;
225
+ } ;
226
+
227
+ snabbtjs . AttentionAnimation . prototype . stop = function ( ) {
228
+ this . _stopped = true ;
229
+ } ;
230
+
231
+ snabbtjs . AttentionAnimation . prototype . stopped = function ( time ) {
232
+ return this . _stopped ;
207
233
} ;
208
234
209
235
snabbtjs . AttentionAnimation . prototype . tick = function ( time ) {
236
+ if ( this . _stopped )
237
+ return ;
210
238
if ( this . spring . equilibrium )
211
239
return ;
212
240
this . spring . tick ( ) ;
@@ -231,5 +259,5 @@ snabbtjs.AttentionAnimation.prototype.current_state = function() {
231
259
} ;
232
260
233
261
snabbtjs . AttentionAnimation . prototype . completed = function ( ) {
234
- return this . spring . equilibrium ;
262
+ return this . spring . equilibrium || this . _stopped ;
235
263
} ;
0 commit comments