Skip to content

Instantly share code, notes, and snippets.

@alanleard
Created December 19, 2011 22:24
Show Gist options
  • Save alanleard/1499197 to your computer and use it in GitHub Desktop.
Save alanleard/1499197 to your computer and use it in GitHub Desktop.
Shake Animation
var win = Ti.UI.createWindow();
function shakeAnimation(view, count, distance, speed) {
var anim1 = Ti.UI.createAnimation({
duration:speed/2,
left:view.left-(distance/2),
curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_IN
});
var anim2 = Ti.UI.createAnimation({
duration:speed,
left:view.left+distance,
autoreverse:true,
repeat:count,
curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_IN_OUT
});
var anim3 = Ti.UI.createAnimation({
duration:speed/2,
left:view.left+(distance/2),
curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_OUT
});
view.animate( anim1 );
anim2.addEventListener('complete',function(){
view.animate( anim3 );
});
anim1.addEventListener('complete',function(){
view.animate( anim2 );
});
}
var view = Ti.UI.createView({
backgroundColor:'blue',
height:57,
width:57,
borderRadius:5,
borderColor:'white',
borderWidth:3,
left:132,
top:212
});
win.add(view);
view.addEventListener('click',function(){
shakeAnimation(view,5,10,100);
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment