Skip to content

Commit 74a62fa

Browse files
author
daniel-lundin
committed
Change pos to position, rot to rotation in API. Fix bug when animating multiple elements in one call
1 parent 09044a3 commit 74a62fa

File tree

5 files changed

+51
-34
lines changed

5 files changed

+51
-34
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Fast animations with Javascript(Work in progress)
99
Basic usage
1010
-----------
1111
snabbt(element, {
12-
pos: [100, 0, 0],
13-
from_rot: [-Math.PI, 0, 0],
12+
position: [100, 0, 0],
13+
from_rotation: [-Math.PI, 0, 0],
1414
duration: 700,
1515
});
1616

@@ -20,13 +20,13 @@ Chaining animations
2020
Animation can be chained by using the `then()`-method on the returned animation object. all from_xxx properties will be set to the end state of the previous animation.
2121

2222
snabbt(element, {
23-
pos: [100, 0, 0],
23+
position: [100, 0, 0],
2424
duration: 500,
2525
easing: 'cos',
2626
}).then({
27-
pos: [100, 100, 0],
28-
from_rot: [0, 0, -Math.PI],
29-
rot: [0, 0, Math.PI],
27+
position: [100, 100, 0],
28+
from_rotation: [0, 0, -Math.PI],
29+
rotation: [0, 0, Math.PI],
3030
duration: 1000,
3131
delay: 500,
3232
callback: function() { console.log('animation done'); }
@@ -36,14 +36,14 @@ Animation can be chained by using the `then()`-method on the returned animation
3636
Options
3737
-------
3838

39-
- `from_pos`: Start position ([x, y, z])
40-
- `pos`: End position
41-
- `from_rot`: Start rotation ([a, b, c])
42-
- `rot`: End rotation
39+
- `from_position`: Start position ([x, y, z])
40+
- `position`: End position
41+
- `from_rotation`: Start rotation ([a, b, c])
42+
- `rotation`: End rotation
4343
- `from_scale`: Start scale ([x, y])
4444
- `scale`: End scale
45-
- `from_rot_post`: Start rotation applied after `pos` and `rot` ([a, b, c])
46-
- `rot_post`: End rotation applied after `pos` and `rot`
45+
- `from_rotation_post`: Start rotation applied after `position` and `rotation` ([a, b, c])
46+
- `rotation_post`: End rotation applied after `position` and `rotation`
4747
- `from_width`: Start width in pixels (single value)
4848
- `width`: End width in pixels
4949
- `from_height`: Start height in pixels (single value)

dist/jquery.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.

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/main.js

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ function snabbt(arg1, arg2, arg3) {
2020

2121
var anim_options = snabbtjs.setup_animation_options(start, end, options);
2222
var animation = snabbtjs.create_animation(anim_options);
23-
snabbtjs.running_animations.push([element, animation]);
23+
24+
if(element.hasOwnProperty('length')) {
25+
for(var i=0;i<element.length;++i) {
26+
snabbtjs.running_animations.push([element[i], animation]);
27+
}
28+
} else {
29+
snabbtjs.running_animations.push([element, animation]);
30+
}
2431

2532
animation.update_element(element);
2633
var queue = [];
@@ -117,10 +124,20 @@ snabbtjs.current_animation_transform = function(element) {
117124
for(var i=0;i<snabbtjs.running_animations.length;++i) {
118125
var animated_element = snabbtjs.running_animations[i][0];
119126
var animation = snabbtjs.running_animations[i][1];
120-
if(animated_element === element) {
121-
var state = animation.current_state();
122-
animation.stop();
123-
return state;
127+
if(element.hasOwnProperty('length')) {
128+
for(var j=0;j<element.length;++j) {
129+
if(animated_element === element[j]) {
130+
var state = animation.current_state();
131+
animation.stop();
132+
return state;
133+
}
134+
}
135+
} else {
136+
if(animated_element === element) {
137+
var state = animation.current_state();
138+
animation.stop();
139+
return state;
140+
}
124141
}
125142
}
126143
};
@@ -129,24 +146,24 @@ snabbtjs.state_from_options = function(p, options, prefix) {
129146
if(!p)
130147
p = new snabbtjs.State({});
131148

132-
if(options[prefix + 'pos']) {
133-
p.x = options[prefix + 'pos'][0];
134-
p.y = options[prefix + 'pos'][1];
135-
p.z = options[prefix + 'pos'][2];
149+
if(options[prefix + 'position']) {
150+
p.x = options[prefix + 'position'][0];
151+
p.y = options[prefix + 'position'][1];
152+
p.z = options[prefix + 'position'][2];
136153
}
137-
if(options[prefix + 'rot']) {
138-
p.ax = options[prefix + 'rot'][0];
139-
p.ay = options[prefix + 'rot'][1];
140-
p.az = options[prefix + 'rot'][2];
154+
if(options[prefix + 'rotation']) {
155+
p.ax = options[prefix + 'rotation'][0];
156+
p.ay = options[prefix + 'rotation'][1];
157+
p.az = options[prefix + 'rotation'][2];
141158
}
142159
if(options[prefix + 'skew']) {
143160
p.skew_x = options[prefix + 'skew'][0];
144161
p.skew_y = options[prefix + 'skew'][1];
145162
}
146-
if(options[prefix + 'rot_post']) {
147-
p.bx = options[prefix + 'rot_post'][0];
148-
p.by = options[prefix + 'rot_post'][1];
149-
p.bz = options[prefix + 'rot_post'][2];
163+
if(options[prefix + 'rotation_post']) {
164+
p.bx = options[prefix + 'rotation_post'][0];
165+
p.by = options[prefix + 'rotation_post'][1];
166+
p.bz = options[prefix + 'rotation_post'][2];
150167
}
151168
if(options[prefix + 'scale']) {
152169
p.sx = options[prefix + 'scale'][0];

src/state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ snabbtjs.State = function(config) {
1717
this.sy = snabbtjs.option_or_default(config.sy, 1);
1818
this.width = config.width;
1919
this.height = config.height;
20-
this.opacity = config.opacity;
20+
this.opacity = snabbtjs.option_or_default(config.opacity, 1);
2121
};
2222

2323
snabbtjs.State.prototype.clone = function() {

0 commit comments

Comments
 (0)