0
votes

I'm new in titanium and I have a strange problem with animate, the code is like this.

var animateRight = Ti.UI.createAnimation({
    left : 150,
    curve:Titanium.UI.ANIMATION_CURVE_EASE_IN_OUT
});

var animateStart = Ti.UI.createAnimation({
    left : 0,
    curve:Titanium.UI.ANIMATION_CURVE_EASE_IN_OUT
});


$.menu.addEventListener('click', function(){
    if($.container.left >= 10){
        //$.container.left = 0;
        $.container.animate(animateStart);  
    }
else{
    //$.container.left = 150;
    $.container.animate(animateRight);
}
});

menu is a button, when I touch it, the menu should move to right, and if a touch it again the menu should move to left, so if a use "$.container.left = 150;",the action in the menu work well, but if use animate the menu never return to original position.

I think that the problem is for the animate, but I'm not sure, somebody can I help me ?

Thanks.

2

2 Answers

0
votes

Animation is perfectly fine.I think there is something wrong with your condition.Checkout whether both conditions work by showing an alert

Thanks

0
votes

you can use Boolean variable to control animation like :

var is_container_change = false;

var animateRight = Ti.UI.createAnimation({
   left : 150,
   curve:Titanium.UI.ANIMATION_CURVE_EASE_IN_OUT
});

var animateStart = Ti.UI.createAnimation({
   left : 0,
   curve:Titanium.UI.ANIMATION_CURVE_EASE_IN_OUT
});

$.menu.addEventListener('click', function(){
   if(is_container_change){
      $.container.animate(animateStart);
   }
   else{
      $.container.animate(animateRight);
   }
   is_container_change = !is_container_change
});