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? Not just about this specific post, but about any topic in front-end development that you'd like to learn more about? If so, feel free to send me a message on Twitter or send me an email. You can find them at the bottom of this page.
I have a long list of upcoming posts, but your questions or ideas for the next one will be my top priority. Let's learn together! Sharing knowledge is the best way to grow 🥷.
Recent posts ⚡
Copy the content of an element to your clipboard
01 Oct, 2023
Make a text area fit its content automatically
30 Sep, 2023
Quickly insert alternate characters while typing
30 Sep, 2023
Zebra-like background
30 Sep, 2023
Add autocomplete to your text area
28 Sep, 2023
Linear scale of a number between two ranges
28 Sep, 2023
Highlight the current line in a text area
27 Sep, 2023
Create your own custom cursor in a text area
27 Sep, 2023
Mirror a text area for improving user experience
26 Sep, 2023
Display the line numbers in a text area
24 Sep, 2023
Select a given line in a text area
24 Sep, 2023
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