Skip to content

Commit

Permalink
add helper function for transform
Browse files Browse the repository at this point in the history
  • Loading branch information
mtbnunu committed Dec 1, 2015
1 parent bd33558 commit 456793e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
20 changes: 20 additions & 0 deletions js/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ animateCss.useJs = !Modernizr.cssanimations;

}(jQuery));

//helpers
animateCss.transform = function (e, o) {
if (Modernizr.csstransforms) {
var str = "";
if (typeof (o.length) !== "undefined") {
for (i = 0; i < o.length; i++) {
str += (o[i].property + "(" + o[i].value + ") ");
}
} else {
str += (o.property + "(" + o.value + ") ");
}
$(e).css('-webkit-transform', str);
$(e).css('-ms-transform', str);
$(e).css('transform', str);
} else {
//no transforms.. what to do..?
console.log("CRY");
}
}

/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*
Expand Down
5 changes: 4 additions & 1 deletion js/bouncing_entrances.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ animateCss.bounceIn = function (e) {
$(e).animate({ asdf: 0 },0)
.animate({asdf: 1}, {
step: function (now, fx) {
$(this).css('-webkit-transform', "scale(" + now + ")");
animateCss.transform(this, {
property: "scale",
value: now
});
},
duration: 1000,
easing: "easeOutElastic"
Expand Down
15 changes: 12 additions & 3 deletions js/bouncing_exits.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@ animateCss.bounceOut = function (e) {
$(e).animate({ asdf: 1 }, 0)
.animate({ asdf: 0.9 }, {
step: function (now, fx) {
$(this).css('-webkit-transform', "scale(" + now + ")");
animateCss.transform(this, {
property: "scale",
value:now
});
},
duration: 70,
easing: "swing",
})
.animate({ asdf: 0 }, {
step: function (now, fx) {
$(this).css('-webkit-transform', "scale(" + now + ")");
animateCss.transform(this, {
property: "scale",
value: now
});
},
duration: 650,
easing: "easeInBack",
complete: function () {
$(e).css('-webkit-transform', "scale(1)");
animateCss.transform(this, {
property: "scale",
value: 1
});
}
})
}
Expand Down

0 comments on commit 456793e

Please sign in to comment.