Skip to content

Commit ff5b9f4

Browse files
author
daniel-lundin
committed
Stop animation command
1 parent 2ec9ecb commit ff5b9f4

File tree

6 files changed

+3882
-1060
lines changed

6 files changed

+3882
-1060
lines changed

dist/jquery.snabbt.min.js

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/snabbt.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/animations.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ snabbtjs.Animation.prototype.assign = function(options) {
2020

2121
this.start_time = 0;
2222
this.current_time = 0;
23+
this._stopped = false;
2324
// Manual related, should probably be subclassed
2425
this.value = 0;
25-
this.cancelled = false;
2626

2727
if(this.mode === snabbtjs.AnimationType.SPRING) {
2828
options.equilibrium_position = 1;
@@ -40,8 +40,19 @@ snabbtjs.Animation.prototype.assign = function(options) {
4040
}
4141
};
4242

43+
snabbtjs.Animation.prototype.stop = function() {
44+
this._stopped = true;
45+
};
46+
47+
snabbtjs.Animation.prototype.stopped = function() {
48+
return this._stopped;
49+
};
50+
4351
snabbtjs.Animation.prototype.tick = function(time) {
4452
// If first tick, set start_time
53+
if(this._stopped)
54+
return;
55+
4556
if(!this.start_time) {
4657
this.start_time = time;
4758
}
@@ -71,11 +82,14 @@ snabbtjs.Animation.prototype.set_value = function(value) {
7182
};
7283

7384
snabbtjs.Animation.prototype.current_state = function() {
74-
this.update_current_transition();
85+
if(!this._stopped)
86+
this.update_current_transition();
7587
return this._current_state;
7688
};
7789

7890
snabbtjs.Animation.prototype.completed = function() {
91+
if(this._stopped)
92+
return true;
7993
if(this.mode == snabbtjs.AnimationType.TIME) {
8094
if(this.start_time === 0) {
8195
return false;
@@ -93,6 +107,9 @@ snabbtjs.Animation.prototype.start_state = function() {
93107
};
94108

95109
snabbtjs.Animation.prototype.end_state = function() {
110+
if(this._stopped)
111+
return this.current_state();
112+
96113
if(this.mode == snabbtjs.AnimationType.TIME || this.mode == snabbtjs.AnimationType.SPRING) {
97114
return this._end_state;
98115
} else {
@@ -196,17 +213,28 @@ snabbtjs.ScrollAnimation.prototype.completed = function() {
196213
};
197214

198215
// ------------------------
199-
// -- AttantionAnimation --
216+
// -- AttentionAnimation --
200217
// ------------------------
201218

202219
snabbtjs.AttentionAnimation = function(options) {
203220
this.movement = options.movement;
204221
this.current_movement = new snabbtjs.State({});
205222
options.initial_velocity = 0.1;
206223
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;
207233
};
208234

209235
snabbtjs.AttentionAnimation.prototype.tick = function(time) {
236+
if(this._stopped)
237+
return;
210238
if(this.spring.equilibrium)
211239
return;
212240
this.spring.tick();
@@ -231,5 +259,5 @@ snabbtjs.AttentionAnimation.prototype.current_state = function() {
231259
};
232260

233261
snabbtjs.AttentionAnimation.prototype.completed = function() {
234-
return this.spring.equilibrium;
262+
return this.spring.equilibrium || this._stopped;
235263
};

src/easing.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ snabbtjs.sinc = function(curr, max) {
7676

7777

7878
snabbtjs.SpringEasing = function(options) {
79-
console.log(options);
8079
this.position = snabbtjs.option_or_default(options.start_position, 0);
8180
this.equilibrium_position = snabbtjs.option_or_default(options.equilibrium_position, 0);
8281
this.velocity = snabbtjs.option_or_default(options.initial_velocity, 0);
@@ -91,7 +90,6 @@ snabbtjs.SpringEasing.prototype.tick = function() {
9190
if(this.equilibrium)
9291
return;
9392
var spring_force = -(this.position - this.equilibrium_position) * this.spring_constant;
94-
//spring_force *= Math.abs(spring_force);
9593
// f = m * a
9694
// a = f / m
9795
var a = spring_force / this.mass;

0 commit comments

Comments
 (0)