Animated websites are pretty cool

Leon Fan
3 min readAug 2, 2021

--

Once the functionality of a web application has been built, the next step is to style the webpages so that only important information is displayed to reduce visual clutter for those who are using the app. Having a good user experience is instrumental to having a successful web application because if you were using a website that is incredibly frustrating to navigate and the overall interface didn’t make much sense, then you probably wouldn’t spend much time on the site.

One way of improving website interactivity is to have the frontend update its state in real time as the backend request is made so that the frontend can reflect the changes that are being made to the backend. This makes it so the website feels extremely responsive and the user can feel how impactful their actions are.

Another way to give a website a very responsive feel is to include animations for certain actions such as having a button change color when its pressed down or other similar animations. Youtube also has thumbnails that autoplay through a snippet of the video when the mouse is hovered over it. To create such interactive websites sounds difficult at first but thankfully, there are a few libraries that help in animating components.

react-spring

One such library is called react-spring named after the fact that their animations are modeled after the behavior of a spring. In doing so, the developers claim that the animations created using react-spring look more dynamic, thus being more natural and smooth than animations created using time intervals and curves.

It is important to note that there is an issue with how npm works so to install react-spring, first install yarn and then use the following command:

yarn add react-spring

Once installed, the library gives access to a few new functions useSpring, useTrail, useTransition, and useChain.

useSpring is pretty intuitive in its naming and creates a spring for the associated component to be animated with, and the animation will follow the physics of the spring. It is also possible to create multiple springs with the function useSprings.

useTrail creates several springs all to the same configuration that stagger their animation to create a trailing effect. This can be used to create an animated trail or to load in components one after another.

useTransition is used to transition between components, usually images, to create a more dynamic experience. An example of this is to cycle between images and have them fade in and out.

Finally, useChain allows for previously established spring animations and transitions to be chained to one another so they animate one after another.

Animations can really help a website feel more familiar to the user and react-spring seems relatively easy to use and by far beats having to write out keyframes to guide the time-based animations and because the animations created by react-spring are physics based, they can move more naturally and don’t have a designated start and stop frame. The spring animations can start and slowly lose momentum and eventually stop.

Find out more at:

https://react-spring.io/

--

--