Notification bubble with CSS3 keyframe animation

The other day, while working on a web project, I had to emphasize somehow a dynamic notification bubble. Basically, every time the notification value changes, a visual effect was needed in order to get user’s attention. So I made that using CSS3 keyframe animation.

Simple notification bubble

View demo

The HTML

For this example, we’ll borrow the markup structure and look from my CSS3 dropdown menu.

<ul class="menu">
    <li><a href="">Dashboard</a></li>
    <li><a href="">Stats</a></li>
    <li>
    	<a href="">
    		Todo list
    		<span class="bubble">9</span>
    	</a>
    </li>
    <li><a href="">Settings</a></li>
</ul>

The focus will be on the <span class="bubble">, which is the notification bubble that will be animated.

The CSS

The .animating class represents an CSS3 animation that uses a bezier curve.

.animating{
	animation: animate 1s cubic-bezier(0,1,1,0);			
}

@keyframes animate{
	from {
	   transform: scale(1);
	}
	to {
	   transform: scale(1.7);
	}
}	

The jQuery

It’s not as easy as you might think to restart an animation and Chris Coyier wrote a good article about it.

The method I chose for this example involves using JavaScript’s setTimeout() method. So, every time the notification value changes, the .animating class is removed after a second (exactly how long the proper animation lasts).

In production, you will not need the counterValue variable. This is used just for our working example in order to be able to increment and decrement the notification value.

var counterValue = parseInt($('.bubble').html()); // Get the current bubble value

function removeAnimation(){
	setTimeout(function() {
		$('.bubble').removeClass('animating')
	}, 1000);			
}

$('#decrease').on('click',function(){
	counterValue--; // decrement
	$('.bubble').html(counterValue).addClass('animating'); // animate it
	removeAnimation(); // remove CSS animating class
})

$('#increase').on('click',function(){
	counterValue++; // increment
	$('.bubble').html(counterValue).addClass('animating'); // animate it
        removeAnimation(); // remove CSS animating class 

View demo

Simple, but effective

I think this is a simple and practical example on how to use a CSS3 animation to enhance user experience. Further, you can experiment with the bezier curve values and come up with some other cool effects.

Thanks for reading and looking forward to read your thoughts!

9 thoughts on “Notification bubble with CSS3 keyframe animation

  1. It seems like you always seem to have an idea of something I’m working on on just thinking about putting together and you always do a great job at that. Keep it up. I’m sure we all appreciate your work everytime.

  2. Hi Catalin

    I think you summed up this blog post perfectly with the phrase “Simple, but effective”. The code used here is much simpler then I thought it would need to be to achieve the animation in the demo.
    The styling and colour scheme is also very effective.

    Cathy

  3. the animation is a bit jerky when the incremental/decremental button is pressed… very nice effect however, but how can i make this communicate with my email for instance?

    for instance if i run a community site, i want to be notified when i receive messages, something similar to facebook… would that be hard to achieve?

  4. I have seen such notification bubbles on various websites but never gave a thought about designing one for my website. Its nice to learn how these bubbles can be built through css 3 animation

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>