Skip to content

Commit dd73555

Browse files
author
daniel-lundin
committed
Added staticTransform property
1 parent 1e86d9f commit dd73555

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"mocha": "^2.3.3",
3030
"sinon": "^1.17.1",
3131
"watchify": "^3.4.0",
32-
"uglify-js": "^2.4.24"
32+
"uglify-js": "^2.4.24",
33+
"chai-string": "^1.1.4"
3334
},
3435
"spm": {
3536
"main": "snabbt.js",

src/animation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function createAnimation(startState, endState, options, transformProperty) {
136136
return;
137137
var matrix = tweener.asMatrix();
138138
var properties = tweener.getProperties();
139-
utils.updateElementTransform(element, matrix, transformProperty, properties.perspective);
139+
utils.updateElementTransform(element, matrix, transformProperty, properties.perspective, options.staticTransform);
140140
utils.updateElementProperties(element, properties);
141141
}
142142
};

src/tests/animationTests.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict';
22

33
const sinon = require('sinon');
4-
const expect = require('chai').expect;
4+
const chai = require('chai')
5+
const expect = chai.expect;
6+
chai.use(require('chai-string'));
57
const createAnimation = require('../animation.js').createAnimation;
68
const createState = require('../state.js').createState;
79

@@ -72,5 +74,26 @@ describe('animations', () => {
7274

7375
expect(element.style).to.have.property(transformProperty);
7476
});
77+
78+
it('should default to transform if no transformProperty is passed', () => {
79+
const element = { style: {} };
80+
const animation = createAnimation(startState, endState, {});
81+
82+
animation.updateElement(element, true);
83+
84+
expect(element.style).to.have.property('transform');
85+
});
86+
87+
it('should use set staticTransform if present in options', () => {
88+
const element = { style: {} };
89+
const options = {
90+
staticTransform: 'translateX(100px)'
91+
};
92+
const animation = createAnimation(startState, endState, options);
93+
94+
animation.updateElement(element, true);
95+
96+
expect(element.style.transform).to.startWith(options.staticTransform);
97+
});
7598
});
7699
});

src/utils.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ function optionOrDefault(option, def) {
1111
return option;
1212
}
1313

14-
function updateElementTransform(element, matrix, transformProperty, perspective) {
15-
var cssPerspective = '';
16-
if (perspective) {
17-
cssPerspective = 'perspective(' + perspective + 'px) ';
18-
}
14+
function updateElementTransform(element, matrix, transformProperty, perspective, staticTransform) {
15+
var cssPerspective = perspective ? 'perspective(' + perspective + 'px) ' : '';
1916
var cssMatrix = matrix.asCSS();
20-
element.style[transformProperty] = cssPerspective + cssMatrix;
17+
var cssStaticTransform = staticTransform ? staticTransform : '';
18+
if (transformProperty)
19+
element.style[transformProperty] = cssStaticTransform + cssPerspective + cssMatrix;
20+
else
21+
element.style.transform = cssStaticTransform + cssPerspective + cssMatrix;
2122
}
2223

2324
var updateElementProperties = function(element, properties) {

0 commit comments

Comments
 (0)