Created
May 9, 2014 15:59
-
-
Save benjaminsinger/92ab2fa1c9700bb9a0f4 to your computer and use it in GitHub Desktop.
CSS3 And jQuery Animation Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CSS3 Animations Helper | |
(function($) { | |
var delay = 0; | |
$.fn.translate3d = function(translations, speed, easing, complete) { | |
var opt = $.speed(speed, easing, complete); | |
opt.easing = opt.easing || 'ease'; | |
translations = $.extend({x: 0, y: 0, z: 0}, translations); | |
return this.each(function() { | |
var $this = $(this); | |
$this.css({ | |
transitionDuration: opt.duration + 'ms', | |
transitionTimingFunction: opt.easing, | |
transform: 'translate3d(' + translations.x + 'px, ' + translations.y + 'px, ' + translations.z + 'px)' | |
}); | |
setTimeout(function() { | |
$this.css({ | |
transitionDuration: '0s', | |
transitionTimingFunction: 'ease' | |
}); | |
opt.complete(); | |
}, opt.duration + (delay || 0)); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment