I'm trying to animate translate3d with Jquery 2.1.1. in 10 seconds. Then, when the animation is complete, I want it to alert me. But the problem is that it does not animate. It just changes instantly to the new css.
Is there some hero that can help me with this?
The code i use now:
$( ".circle" ).animate({ textIndent: 100 }, {
duration : 10000,
step : function() {
$(this).css("transform","translate3d(0px, 320px, 0px)");
},
complete : function() {
alert("completed the animation");
}
},'linear');
Basically with animate and transform you have to use the step function of the animate function of jQuery which will look a bit like this:
You would have to set the text-indent separately but basically what you were doing wrong was that every time the step function was called the value was set straight to 320px instead of as it goes. This can be tackled by having two separate functions and using unimportant css rules to create the values needed across the animation curve. You also need to set the queue to false so that the two animations happen at the same time and not one after the other
The final snippet of code would look like this:
Here is a working fiddle:
http://jsfiddle.net/Hive7/1qu2qxqh/
You can use jquery.transit jQuery plugin for css3 transition:
very good plugin and many features
Demo Here