Forum Discussion
[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
- WaltHamiltonSuper Hero
You can use a motion path. Set the start x and y values to the location you want, and the length to 0.
- IvanParascandolCommunity 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-9Community Member
Check my post with attachment and link. This way you can animate anything dynamically.
- IvanParascandolCommunity Member
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.
- PrzemysławHubisCommunity Member
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.
- WillPCommunity 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.
- PrzemysławHubisCommunity Member
It is :)
Sample:
https://slchallenges.s3.eu-west-1.amazonaws.com/JSMoveTest/story_html5.html
Source in the attachment
- Arystian-InglotCommunity Member
Thank you!
- BrianAllenCommunity 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!
Related Content
- 7 months ago
- 12 months ago