Forum Discussion

Arystian-Inglot's avatar
Arystian-Inglot
Community Member
7 years ago

[JS] SET OBJECT POSITION

Hello,

is it possible to set an object position (x,y) using javascript when, for example, user clicks the button?

35 Replies

  • You can use a motion path. Set the start x and y values to the location you want, and the length to 0.

    • IvanParascandol's avatar
      IvanParascandol
      Community Member

      Oh I was asking if there was a way to do it via Javascript, similarly to how it was being done in the example posted by Przemysław Hubisz. I've got some items that I need to move dynamically so I can't use any pre set positions.

      • MathNotermans-9's avatar
        MathNotermans-9
        Community Member

        Check my post with attachment and link. This way you can animate anything dynamically.

  • Is there a way to set the position to an x,y value rather than just translating it from another position? I'd like to move an element to a specific position regardless of where it's original location was.

  • What is funny to select the right item from the array you need to count how high is the element on the timeline. In this example soccer image is on 14th position from the bottom and because in JS array start from 0 position thus I pick 13th element.

    • WillP's avatar
      WillP
      Community Member

      Hi Przemyslaw. Thanks for the tips.

      However, I noticed that when you resize the window to a smaller size the soccer ball goes out of bounds.

      It seems that by using transform/translate, the pixels become realtive to the screen size. So the boundaries you set in your IF statements cease to work.

      Any ideias how to guarantee that a 10px increment (as you set up in your project) remains as a 10px increment no matter what size you screen is?

      Oh, and how did you find out that to storyline objects were defined by layers within an array? That was very helpful for my projects.

    • BrianAllen's avatar
      BrianAllen
      Community Member

      Przemysław, pretty cool... Took me a minute to figure out your example uses the arrow keys on the keyboard, but I like it!