Skip to content

Commit 0497a5d

Browse files
committed
Added support for custom css animations.
1 parent a40f7b4 commit 0497a5d

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

angular-parallax.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,32 @@ directive('duParallax',
3737
}
3838

3939
var translate3d = function(result){
40-
return 'translate3d(' + result.x + 'px, ' + result.y + 'px, 0)';
40+
if(!result.x && !result.y) return '';
41+
return 'translate3d(' + Math.round(result.x) + 'px, ' + Math.round(result.y) + 'px, 0)';
4142
};
4243

4344
var rotate = function(result) {
4445
if(!result.rotation) return '';
45-
return ' rotate(' + result.rotation + (angular.isNumber(result.rotation) ? 'deg' : '') + ')';
46+
return ' rotate(' + (angular.isNumber(result.rotation) ? Math.round(result.rotation) + 'deg' : result.rotation) + ')';
4647
};
4748

4849
var applyProperties = function(result, element) {
4950
element.style[transformProperty] = translate3d(result) + rotate(result);
5051
element.style.opacity = result.opacity;
52+
if(result.custom) {
53+
for(var property in result.custom) {
54+
element.style[property] = result.custom[property];
55+
}
56+
}
5157
};
5258

5359
return{
5460
scope : {
5561
y : '=',
5662
x : '=',
5763
rotation : '=',
58-
opacity : '='
64+
opacity : '=',
65+
custom : '='
5966
},
6067
link: function($scope, $element, $attr){
6168
var element = $element[0];
@@ -68,7 +75,7 @@ directive('duParallax',
6875
elemY: rect.top
6976
};
7077

71-
var properties = { x : 0, y : 0, rotation : 0, opacity: 1};
78+
var properties = { x : 0, y : 0, rotation : 0, opacity: 1, custom: undefined};
7279

7380
for(var key in properties){
7481
if(angular.isFunction($scope[key])){

angular-parallax.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular-parallax.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/parallax.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ directive('duParallax',
1717
}
1818

1919
var translate3d = function(result){
20+
if(!result.x && !result.y) return '';
2021
return 'translate3d(' + Math.round(result.x) + 'px, ' + Math.round(result.y) + 'px, 0)';
2122
};
2223

@@ -28,14 +29,20 @@ directive('duParallax',
2829
var applyProperties = function(result, element) {
2930
element.style[transformProperty] = translate3d(result) + rotate(result);
3031
element.style.opacity = result.opacity;
32+
if(result.custom) {
33+
for(var property in result.custom) {
34+
element.style[property] = result.custom[property];
35+
}
36+
}
3137
};
3238

3339
return{
3440
scope : {
3541
y : '=',
3642
x : '=',
3743
rotation : '=',
38-
opacity : '='
44+
opacity : '=',
45+
custom : '='
3946
},
4047
link: function($scope, $element, $attr){
4148
var element = $element[0];
@@ -48,7 +55,7 @@ directive('duParallax',
4855
elemY: rect.top
4956
};
5057

51-
var properties = { x : 0, y : 0, rotation : 0, opacity: 1};
58+
var properties = { x : 0, y : 0, rotation : 0, opacity: 1, custom: undefined};
5259

5360
for(var key in properties){
5461
if(angular.isFunction($scope[key])){

0 commit comments

Comments
 (0)