top of page
Solar System Animation

Solar System Animation

Create a simplified solar system animation using the Wix Animations API.

Intermediate.png

Advanced

5K

Published:

August 11, 2021

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example we created a simplified solar system animation. Users can click on different buttons to turn certain animations on or off from the solar system. Note that there are some animations that the user can’t turn on or off. The 4 buttons and the animations they trigger are listed below:


  1. Position: Animation of the earth circling around the sun.

  2. Scale: Animation of the earth scaling up and down in size.

  3. Rotation: Animation of the earth and sun rotating in place.

  4. Opacity: Animation of the stars blinking.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

Page Elements

 

In our site we added the following page elements:

  • 3 vector elements to build 3 sets of stars.

  • 2  images for the moon and a copy of the moon.

  • 1 image for the earth.

  • 1 image for the sun.

  • 1 vector image for the orbit.

  • 4 buttons to trigger the different solar system animations.

 

 

Code

 

In the $w.onReady() function we declare all the elements we want to animate, and their measurements. We also make sure to configure the element measurements for mobile devices. We then create the individual animation timelines for each of the animations:

 

  1. moon_tl: Rotate the moon around the earth. Since we can’t change the order of elements with code, we created two copies of the moon: one located behind the earth, and the other in front of it. We then switch between hiding and showing each one every half turn. To keep the order of elements from changing, we need to turn off an accessibility feature in the Editor by going to Settings -> Accessibility -> Advanced Settings -> and unchecking the “Automatic DOM order” checkbox.

  2. system_tl: We group the earth and two moon images together to create a ‘System’ and rotate the System around the sun. We split the rotation into 4 animation segments and create the illusion of a skewed ellipse by changing the duration, easing, and length of each element.

  3. system_scale_tl: Add a scaling effect on the System.

  4. system_rotation_tl: Add a rotation effect on the earth and sun.

  5. starts_tl: We create a system to blink the stars by assigning the 3 star elements to different opacities and durations. We also use the easeOutBounce easing property for a more dramatic effect.

 

We also built a helper timeline to handle all our timelines. We then set the state of the 4 animations, and connect them to the relevant timelines. Then we run over all the state timelines and restart or pause them depending on their state.

 

In the $w.onReady() function we created the constants above and assigned the needed animations to them. We also created a constant object to save the state of the 4 button animations and connect them to the relevant timeline. This is based on a timeline that hides the System, runs changes at the end of the animation, and then shows the System again.

 

Last, we created onClick() event handlers for the different buttons. Each event handler sets a new state and replays the restart timeline.

APIs We Used

Non-code example.

Non-code example.

Related Articles

Article Link

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Custom Button Animation

Custom Button Animation

Create a custom button that rotates clockwise and changes color on click using the Wix Animations API.

Intermediate.png

Beginner

Hourglass Animation

Hourglass Animation

Flip an hourglass automatically or on a button click using the Wix Animations API.

Intermediate.png

Advanced

Ball Drop Animation

Ball Drop Animation

Create a ball drop animation where balls fall through a maze and dot the letter I’s in your words.

Intermediate.png

Advanced

Text Microinteractions

Text Microinteractions

Create different microinteractions on 3 text elements using the Wix Animations API.

Intermediate.png

Intermediate

Vector Image Animation

Vector Image Animation

Create an animation of a ball moving and then taking the place of the letter O’s in your words.

Intermediate.png

Beginner

Anchor 2

This website was designed with Velo by Wix

bottom of page