Pulse animation
Written byPhuoc Nguyen
Created
23 Aug, 2023
A pulse animation effect is a type of animation that creates a pulsating and fading effect. It is often used to draw users attention to an element on a web page or in an app, such as a button or notification.
To create a pulsing effect, we increase the size of an element and then gradually decrease it back to its original size. For a fading effect, we can adjust the element's opacity.
Here's an example of how it looks using the
`transform: scale`
and `opacity`
properties.In reality, this animation only requires two circles. The inner circle remains the same in terms of size and opacity, while the outer circle undergoes all the modifications.
Now, let's explore some common methods for creating this type of layout.
#Using the box shadow
Creating a fake outer circle is possible without having to make two separate circles. The secret lies in using the
`box-shadow`
property.#Using pseudo-elements
Using the pseudo-elements
`::before`
and `::after`
is a great way to represent inner and outer circles. By positioning them absolutely, they can take up the full size of the original element.styles.css
.circle {
position: relative;
}
.circle::after,
.circle::before {
content: '';
/* Position absolutely */
position: absolute;
left: 0;
top: 0;
/* Take full size */
height: 100%;
width: 100%;
border-radius: 9999px;
}
Check out the demo below, which showcases the animation on the
`::before`
element.#Usages
We can grab the user's attention with the pulse animation in specific areas. Let me give you some common examples.
User Onboarding
When a user visits your website for the first time, it's important to show them how to explore and get the most out of your site. This is known as user onboarding. It's also a great opportunity to introduce new features of your Sass-based application.
Notification badges
We can display a notification badge at the top-right corner of an element. This is used in many applications such as:
- An email client to show how many unread emails you have in your inbox,
- A messenger application to show how many unread messages you have,
- An online store to show how many customers you had in the last day.
#See also
Questions? 🙋
Do you have any questions about front-end development? If so, feel free to create a new issue on GitHub using the button below. I'm happy to help with any topic you'd like to learn more about, even beyond what's covered in this post.
While I have a long list of upcoming topics, I'm always eager to prioritize your questions and ideas for future content. Let's learn and grow together! Sharing knowledge is the best way to elevate ourselves 🥷.
Recent posts ⚡
Newsletter 🔔
If you're into front-end technologies and you want to see more of the content I'm creating, then you might want to consider subscribing to my newsletter.
By subscribing, you'll be the first to know about new articles, products, and exclusive promotions.
Don't worry, I won't spam you. And if you ever change your mind, you can unsubscribe at any time.
Phước Nguyễn