1 Reply Latest reply on Nov 12, 2013 2:51 AM by elainecc

    Position of elements with "animate"




      I would like to slide elements on click adding 500 px on Y, onclick. I used this but the element goes to pos 500 and not add 500px from is actual position.




      Where is my mistake ?





        • 1. Re: Position of elements with "animate"
          elainecc Adobe Employee

          Hi, Raff-


          The problem is that you're trying to add to what is probably a string.  Here's some code that worked for me:


          // given the element "moveMe"

          var currX = parseInt(sym.$("moveMe").css("left"));

          var newX = currX + 50;

          var myX = newX.toString() + "px";

          sym.$("moveMe").animate({left: myX}, 500);



          As you can see, I stripped off the "px" using parseInt, added 50, and then put the "px" back on.  There's probably more streamlined code I could write to make it all in one line or so, but I kept it separate for readability.


          Hope that helps,



          1 person found this helpful