Using CSS and GIF’s to animate a menu
June 16, 2008 @ 6:16 pm | Comments (21)
Remember our good old friend the animated gif? There was a time when the ability to animate GIF’s made web sites a little more fun… or horribly obnoxious. It seems that no one really harnessed the power of animated GIFs, and today the only place they seem to be used are in banner advertisements when flash isn’t available.
GIFs can still be a very powerful tool, and the fact that they have been long forgotten gives me an opportunity to brainstorm what you can do with them.
One of the more powerful capabilities of CSS is the use of the :hover pseudo selector. It is one of the only abilities we have to alter the behavior of a website simply through XHML and CSS (and there is a debate if this even should be done, but this is more about capabilities rather than theoretical debates of what should/shouldn’t be done).
Because IE6 has shoddy :hover support on non anchor elements, the most logical place to use this combination of :hover and animated GIFs will be in a menu item. However you could easily use this same technique on any element and just count on the modern browsers being able to take advantage of it.
The Plan
So what we want to do is have an item appear static on the page, until we hover over it. Once hovered it will start a simple animation to enhance the interactivity of the site.
For this example we will be creating a menu, each menu item will have a little glow below it. When someone hovers over it we want the glow to pulse and some stars to rise from it - kinda magical or something along those lines.
THE TECHNIQUE
We will be using CSS Roll-overs to produce this effect. The trick with CSS Roll overs is to create an image that has both image states (the non-hover state and the hover state) in the same image. Then when you hover over the link it shifts the background-position of the roll over to reveal the hover state below.

Here is an example of the normal state (the left side), and the hover state (the right side)
We use this method over a different image on the hover state because many browsers get a flicker the first time you switch the images.
The basic code:
#main_nav a {
display: block;
width: 150px;
height: 150px;
background: url(menu.gif); }
#main_nav a:hover { background-position: -150px 0; }
Essentially all you do is shift the background image one cell over (150pixels, the width of the tab) and it shows the hovered state.
THE ANIMATION
Using photoshop we can pretty easily create an animated GIF. I am not going to teach you how to do it, but if you don’t know how read this tutorial. Now what we are going to do is create an animated gif of the same navigation tab above, but only have one side/state animated.
We end up creating 15 frames which the animation cycles through, here are a few so you get the idea:



When the item isn’t hovered on it looks stationary, despite the fact that the hidden area is in an animated loop the whole time. When we hover over the item it pulls the animated portion into view where it causes the stars to move upward and the glow to pulse.
THE LIMITATIONS
Because we can only set it to either loop once (which it loops immediately and we miss it) or repeat we can only do animations that have a seamless loop. Additionally since the animation is looping all the time we are somewhat limited in the animation because someone might hover over the element at the furthest frame from the start creating a bit of a jump. So the animation has to be subtle (which is good anyways, lets not take animation too far.)
Example Page
DOWNLOAD EXAMPLE FILES + TEMPLATE
« We as web developers need to be creative in our messaging… Adobe Acrobat 9, making web design / development easier? »



COMMENT Gautch
This is awesome! I’ve been playing with div’s having background images in flash to kind of create this same affect, but it seems you can do it with gifs. Nice work!
-Gautch
Posted on 06/17 1:08am
COMMENT Jarrod - Warrior Development
That is very cool. I’ll have to start into how I can use that method on my sites.
Posted on 06/17 1:39am
COMMENT Diseñar un menú con movimiento con CSS y un GIF animado » Cosas sencillas
[…] el blog 3.7 Designs, nos recuerdan que en cuanto a los Gifs animados, hubo un tiempo en que aprovechando la capacidad […]
Posted on 06/17 4:11am
COMMENT ross
Thanks Jarrod and Guatch, I think there are tons of possibilities for the technique. I am really curious to see what others come up with in terms of using it. Keep me posted of any site you end up using it on! =)
Posted on 06/17 8:23am
COMMENT For the love of gifs. » Blog Archive » AjaxLine Talkin Gifs
[…] articles on making animated gif menus using css. 3.7designs has an overview of using css and gifs to animate menus. AjaxLine article talks about using CSS and animated gifs to animate […]
Posted on 06/17 3:39pm
COMMENT Weblimite | Recursos por un tubo » Blog Archive » Menú animado usando CSS y imagenes GIF
[…] Tutorial: http://www.3point7designs.com/blog/2008/06/16/using-css-and-gifs-to-animate-a-menu/ […]
Posted on 06/18 1:33pm
COMMENT 20 soluciones a problemas comunes de CSS, 60 ridiculously useful tools for your blog or website, SenCSS CSS Framework, 25 Websites With Beautiful Background, Web Design Resource for Free Patterns, Backgrounds and Textures, jQuery For Absolute Beginners, U
[…] Using CSS and GIF’s to animate a menu […]
Posted on 06/18 2:43pm
COMMENT Fatih HayrioÄŸlu'nun not defteri » 19 Haziran 2008 web’den seçeme haberler » Vista, Aero, düÄŸmelerine, düÄŸme, oluÅŸturmak, BaÄŸlantıÂ, yazarları, için, Firefox, WordPress
[…] Güzel bir animasyonlu(gif) menü örneÄŸi. BaÄŸlantı […]
Posted on 06/19 3:53am
COMMENT antosole
Really nice, tank you very much!
Posted on 06/19 7:42am
COMMENT Joshua Clanton
Excellent idea! I’ve now got a few concepts for using animated gifs floating around in my head.
Just subscribed to your RSS feed.
Posted on 06/19 11:21am
COMMENT ross
Thanks Joshua, I am excited to see what ideas people can pull out of this. I haven’t totally figured out all the situations where you can really enhance the interactivity of a site but I am brainstorming some ideas.
Keep me updated on what you have done, I would like to do a post that showcases some great uses of this technique in the future.
Posted on 06/19 11:48am
COMMENT gifs
[…] the ability to animate GIF??s made web sites a little more fun?? or horribly obnoxious. It seems thhttp://www.3point7designs.com/blog/2008/06/16/using-css-and-gifs-to-animate-a-menu/Usenet deletion: alt.* Groups, Others Gone Web Host DirectoryVerizon Communications confirmed on […]
Posted on 06/19 4:31pm
COMMENT Great Resources Elsewhere: June 09 to June 16 - CSSnewbie
[…] » Using CSS and GIF’s to animate a menu - Web Design Marketing Podcast & Blog […]
Posted on 06/20 3:01am
COMMENT website design techniques
[…] the ability to animate GIF??s made web sites a little more fun?? or horribly obnoxious. It seems thhttp://www.3point7designs.com/blog/2008/06/16/using-css-and-gifs-to-animate-a-menu/Taconic, TaconicArtemis, and PhenoPro Form Alliance to Offer Integrated Model Design, Generation, […]
Posted on 06/20 3:56am
COMMENT css ve gif in animasyon menü için kullanımı — World car insure
[…] Burada css ve gif kullanarak yapılmış güzel bir animasyon menünün nası yapıldığı anlatılmış ve ayrıca demosu da verilmiÅŸ. iyi çalışmalar. […]
Posted on 06/20 6:35am
COMMENT 0 n 8 = ? » Blog Archive » css ve gif in animasyon menü için kullanımı
[…] Burada css ve gif kullanarak yapılmış güzel bir animasyon menünün nası yapıldığı anlatılmış ve ayrıca demosu da verilmiÅŸ. iyi çalışmalar. […]
Posted on 06/20 7:06am
COMMENT Andy Ford
It’s strange that this technique is not often used or discussed because it’s one of the cooler things you can do with simple rollovers (as long as it’s done in good taste!).
Posted on 06/20 10:42am
COMMENT Ross Johnson
Yeah I am pretty surprised as well Andy. It was one of those ideas where I thought of it, and then figured SOMEONE has to have done it before… only I couldn’t find it anywhere. Hopefully we will see it used more often from here on out.
Posted on 06/20 2:02pm
COMMENT flash tutorial frames
[…] It seems that no one really harnessed the power of animated GIFs, and today the only place theyhttp://www.3point7designs.com/blog/2008/06/16/using-css-and-gifs-to-animate-a-menu/kirupa.com - Flash & HTML FramesThat is where this tutorial comes in. You will learn how to […]
Posted on 07/08 7:56pm
COMMENT background loops
[…] It seems that no one really harnessed the power of animated GIFs, and today the only place theyhttp://www.3point7designs.com/blog/2008/06/16/using-css-and-gifs-to-animate-a-menu/melodyloops - royalty-free background musicMelodyLoops - complete music solution for a short and […]
Posted on 08/03 2:57pm
COMMENT Using CSS and GIF’s to animate a menu
[…] more powerful capabilities of CSS is the use of the :hover pseudo selector. Permalink to Website: Visit Article Date Filed: Tuesday, July 1st, 2008 Filed under: Featured Web Trends, Web Element Next Post: 10 […]
Posted on 08/14 2:35am