I'm currently writing an application using Zepto and phonegap, and I need to know how to call a function when an animation ends. Unfortunately, I can't really figure it out from the examples given or the documentation. So far, the closest I've been able to e is:
$('img').anim({ translatex: '500px', translatey: '500px', opacity: 1, plete: alert("Hello!") }, 2, 'linear');
Which will trigger the alert before the animation. Does anyone know how to fix this so that the alert will trigger after?
I'm currently writing an application using Zepto and phonegap, and I need to know how to call a function when an animation ends. Unfortunately, I can't really figure it out from the examples given or the documentation. So far, the closest I've been able to e is:
$('img').anim({ translatex: '500px', translatey: '500px', opacity: 1, plete: alert("Hello!") }, 2, 'linear');
Which will trigger the alert before the animation. Does anyone know how to fix this so that the alert will trigger after?
Share Improve this question asked Jan 11, 2012 at 21:28 CSturgessCSturgess 1,5572 gold badges13 silver badges29 bronze badges2 Answers
Reset to default 8The callback function should be the last parameter of the anim call and you should wrap the alert in a function expression:
$('img').anim({
translatex: '500px',
translatey: '500px',
opacity: 1
}, 2, 'linear', function() { alert("Hello!") } );
One other possibility to help here is webkitTransitionEnd - http://www.cuppadev.co.uk/the-trouble-with-css-transitions/