The Blog

Create a Realistic Hover Effect With jQuery

For one of the projects I’m currently working on with Rareview, we wanted to add a rising hover effect to a set of icon links. Using jQuery’s animate effect, I experimented with icons that have reflections and others with shadows. Here is a demo with two examples:

jquery-rising-hover-2

The HTML and CSS are both straightforward and have a structure and style common to many web navigations and menus (for the sake of post length, I’m not including HTML/CSS code examples here but you are free to snoop around in the demo or view the files in the download below).

In a nutshell, the JS appends the reflection/shadow to each <li>, then animates the position and opacity of these elements and the icon links on hover. I’ve added .stop() to eliminate any queue buildup from quickly mousing back and forth over the navigation.

// Begin jQuery
 
$(document).ready(function() {
 
/* =Reflection Nav
-------------------------------------------------------------------------- */	
 
    // Append span to each LI to add reflection
 
    $("#nav-reflection li").append("");	
 
    // Animate buttons, move reflection and fade
 
    $("#nav-reflection a").hover(function() {
        $(this).stop().animate({ marginTop: "-10px" }, 200);
        $(this).parent().find("span").stop().animate({ marginTop: "18px", opacity: 0.25 }, 200);
    },function(){
        $(this).stop().animate({ marginTop: "0px" }, 300);
        $(this).parent().find("span").stop().animate({ marginTop: "1px", opacity: 1 }, 300);
    });
 
/* =Shadow Nav
-------------------------------------------------------------------------- */
 
    // Append shadow image to each LI
 
    $("#nav-shadow li").append('<img class="shadow" src="images/icons-shadow.jpg" alt="" width="81" height="27" />');
 
    // Animate buttons, shrink and fade shadow
 
    $("#nav-shadow li").hover(function() {
    	var e = this;
        $(e).find("a").stop().animate({ marginTop: "-14px" }, 250, function() {
        	$(e).find("a").animate({ marginTop: "-10px" }, 250);
        });
        $(e).find("img.shadow").stop().animate({ width: "80%", height: "20px", marginLeft: "8px", opacity: 0.25 }, 250);
    },function(){
    	var e = this;
        $(e).find("a").stop().animate({ marginTop: "4px" }, 250, function() {
        	$(e).find("a").animate({ marginTop: "0px" }, 250);
        });
        $(e).find("img.shadow").stop().animate({ width: "100%", height: "27px", marginLeft: "0px", opacity: 1 }, 250);
    });
 
// End jQuery
 
});

Please note, for the purposes of this quick demo, I did not bother including support for IE6.

View Demo or Download

Update 06/01/2009: I updated the shadow example so that it has more of a bounce to it.

Update 07/08/2009: As Cody Lindley points out in the comments (thanks!), this example does not require the UI and could work with jQuery alone (I’ve updated the link in the post). However, this being a navigation example, I’ll leave the UI script in the demo and download for users who want to experiment with animating text, background, borders, or outline colors.

193 Comments

Feel free to join the discussion! Leave a Comment

  1. caleb says:

    Nice job… the shadow effect especially looks superb.

  2. Zafar Majid says:

    Brought a smile to my face.

    Not sure which one I prefer, the shadow or the reflection – both look great.

  3. Jermaine says:

    very good stuff Adrian…will certainly be taking advantage of this tutorial. thanks for sharing.

  4. Tristan says:

    That’s really cool Adrian. I just started using jQuery for a project rebuilding my Sensai’s website (www.wm-ma.com). I’ve gotta say, it saves a lot of time vs. regular Javascript development!

  5. cody lindley says:

    Nice work! One small clarification. animate() is part of jQuery core. jQuery UI is not needed.

  6. BJ Neilsen says:

    REALLY like the look of this! Well done!

  7. Adrian says: (Author)

    @Cody: You’re absolutely right, thank you for catching that! The demo above does not require the UI and could work with jQuery alone. I suppose if you wanted to add text to the navigation, or a border/background color, then the UI would be useful in animating color changes.

  8. Paul says:

    I feel I should point out that although the effect looks cool, the fact that the shadows get smaller is not scientifically correct. :)

  9. Adrian says: (Author)

    @Paul: Haha, right you are. Good thing this is only a demo ;)

  10. battisti says:

    very godd effect, probably i will use it someday ;) thx

  11. really nice effect jquery rock and i bookmarked this link.

  12. wrigs says:

    Absolutely superb – looks really stunning. Good job!

  13. John Goode says:

    I prefer the shadow design. Very cool, thanks for sharing

  14. Xavier says:

    Fantastic!! it’s really real!! ;) Thanks for share it!!

  15. Very cool man! jQuery rocks…just starting to get into it. Like the design of your site too, nice typography!

    ~ David

  16. naesk says:

    Cool effects! Thanx for sharing :)

  17. russ says:

    pretty nifty–Q: how do you get your text visible on the button?

  18. Adrian says: (Author)

    @russ: If you check out the HTML, the link text is inside the anchor tag. For this example, I added a large text-indent and hidden overflow so the text wouldn’t be visible with the icons. You could, of course, change this and set it up however you want.

  19. text-indent and hidden overflow so the text wouldn’t be visible with the icons.

  20. Jaime says:

    whoa, shadow rules!

  21. Dave Reeder says:

    Wow this is great, I can see myself using this effect. Very nice and smooth, even in Firefox 2 with all my add-ons.

  22. Aaron says:

    Trying to get it to work with my horizontal navigation, but not having any luck. Any suggestions (im implementing in my given website).

  23. Greg says:

    This really looks great. Nice and usefull tutorial

  24. yAnTar says:

    Very nice work. Thank you.

  25. Gites France says:

    Love it thanks – makes all the difference when you can add shaddow.

  26. Hey, good work!

    You NEED to port this over to Moo!

    Josh

  27. LML says:

    http://www9.speedyshare.com/data/283223742/17971670/21853130/Unbenannt3.JPG

    if you move your mouse fast between two of them, this might happen!:O
    and usualy all the way to the right

  28. Jamie says:

    Great effect. I’ll have to use it on my web design portfolio soon. Please keep em coming!

  29. This is not an original idea: we have developed this effect for our website http://www.informinds.com (published on 14 october 2008) . This is visible in the section “Prodotti” :)

  30. David says:

    Nice!
    It doesn’t work on Google Chrome though, dunno why…

  31. Marcio says:

    Oh! Very nice job, its great!

    Thanks for share!

    Marcio.

  32. Anton says:

    Absolutely Brilliant!! I love the Bouncy shadow version, and the sound effect is a nice touch too!

  33. Israel Bravo says:

    Very nice script, but …. I don’t see the “Link text” in the demo page !
    (Linux, Firefox 3.5.3).

  34. Bravo says:

    Hey, where is the link text (Link Text) in the demo ?
    I don’t see it ! And the moving pictures don’t give me any information!

  35. fajarfaqih says:

    Wow, this could be useful for me ^_^. Thanks so much adrian !!!

  36. Mo says:

    That is awesome. Well done.

  37. Bill Ludwig says:

    That looks awesome! I’m glad I found this.

  38. Adrian says: (Author)

    @Informinds Consulting: Nope, the hover effect is not a groundbreaker but one big difference between your example and mine is your site uses flash, whereas my demo is a combination of HTML, CSS, and Javascript.

    @David: There should be no issues with Chrome.

    @everyone looking for text: I have the text hidden using a large indent and hidden overflow in the CSS. This is a demo only; feel free to make your own edits to include text if you want.

  39. conan says:

    Look nice :)

  40. Masoud says:

    I love this,but, i think its better to do this without make a single reflect for each image!!!

    so i combine this solution with reflect plugin ( see this : http://docs.jquery.com/Plugins:reflect )

    you can see my demo here :

    http://daneshpour.org/jquery/ref_ani/

    I hope this will be usefull !

  41. Eric says:

    Hey bro – nice job! I implemented it, and it works perfect. However, I have one question, do you happen to know why when you use a .png for the “shadow” IE (all versions) blows up the shadow to ten times it’s original size. On first load, before hover, it’s fine.

    I tested this in yours, without changing a single thing, just to be sure, and IE does the same in your demo. Any ideas why? Thanks for your time!

  42. Eric says:

    OK, the problem is caused by the opacity code below. If I remove it, the IE7/8 problem goes away. But, then I loose part of the effect. Any way to write that so IE is happy with the opacity??? Thanks!

    $(document).ready(function() {
    // Append shadow image to each LI
    $(“#nav li”).append(”);
    // Animate buttons, shrink and fade shadow
    $(“#nav li”).hover(function() {
    var e = this;
    $(e).find(“a”).stop().animate({ marginTop: “-14px” }, 250, function() {
    $(e).find(“a”).animate({ marginTop: “-10px” }, 250);
    });
    $(e).find(“img.shadow”).stop().animate({ width: “85px”, height: “20px”, marginLeft: “10px”, opacity: 0.25 }, 250);
    },function(){
    var e = this;
    $(e).find(“a”).stop().animate({ marginTop: “4px” }, 250, function() {
    $(e).find(“a”).animate({ marginTop: “0px” }, 250);
    });
    $(e).find(“img.shadow”).stop().animate({ width: “105px”, height: “27px”, marginLeft: “0″, opacity: 1 }, 250);
    });
    });

  43. Lin says:

    Hi,
    This tutorial is simply awesome.
    I have a problem though. In this demo, images do not change form or color when they are hovered over. But I need that effect, such that when the user hovers over the image, the image color changes(thats just a matter of changing the image on hover ). I have been successful in doing it so far, but there is this one problem. When i hover, the color changes, but when I move the mouse back, (I am still in the hover function), the image takes its original color… sort of like a flickering effect. Could you please tell me how to retain the hover effect even when a user moves the mouse away ?

  44. @Adrian: Nope, in our website there is no Flash, only HTML, CSS, and Javascript too. So, it’s not an original idea. ;)

    Quote:
    @Informinds Consulting: Nope, the hover effect is not a groundbreaker but one big difference between your example and mine is your site uses flash, whereas my demo is a combination of HTML, CSS, and Javascript.

  45. Adrian says: (Author)

    @Informinds: My mistake, you have a very flash-like website ;) At any rate, the point of this tutorial was simply to show a code example of how to achieve an effect I liked. You’re more than welcome to write your own tutorials for your “original” idea.

  46. nice..it smoot animated. thank for code download

  47. Tung says:

    Thanks, really cool!!!

  48. Hi Adrian,

    First, thanks for the great effect! I’m using it in this new site: http:bendmagic.com.

    My problem is with IE7 & 8…the shadows become opaque on hover. As I understand (and I’m no js guru) IE has trouble with opacity changes in png files. Is there a way to fix this for IE7 & 8? (Or must I live with it?) I cannot use .jpgs like your example did because of the pattern behind icons.

    Works great in all other browsers!

  49. Adrian says: (Author)

    @Catherine: IE creates a nasty “black border” when animating PNGs. You might want to google “IE PNG fade” to learn more about the issue and possible solutions. For this demo, I bypassed the issue by using JPGs.

  50. Simples and effective script. Thanks for share.

  51. Rheza says:

    Wow… It’s really amazing… Thank you very much…

  52. faisal amir says:

    good tutorial.. thanks

  53. Wow…the shadow one…very nice :) like this so much….

  54. Drew says:

    Adrian,

    is there a way to make each icon a different width and have it animate? (different sized buttons for my menu)

  55. Mike says:

    If you are going to us png’s for the shadow, and it keeps blowing up when you hover, all you need to do is remove the opacity settings from the ‘execute.js’ script.
    Be sure to remove the comma and value:
    ……… marginTop: “18px”, opacity: 0.25}
    should become:
    ……… marginTop: “18px”}
    the shadow doesnt fade, but it also doesnt blow up

  56. Shawn says:

    You have a really nice site, respect, and your code is beautiful. There is just something really great about doing something so obviously well.

  57. WPbud says:

    One word. awesome.

  58. Wow. amazing. I love it.
    We’ll give it a try.

    F.

  59. Glombiowski says:

    Nice… the shadow effect especially looks superb.

  60. Indialike says:

    Very nice and useful tutorials for web designers,
    Thanks for posting.

  61. rohit says:

    Very nice tutorial for Web designers…but have you checked for the cross browser..? This is not working in IE6.

    Thanks for posting.

  62. Benje says:

    That’s a great effect. I might use it in one of my upcoming themes. :)

  63. Coolz man, so wonderfull effects.

  64. Great one says:

    Is there a way to make it totally transparent, I’m having a hard time finding where to fix it in the css ore in the .js if you cold give me a clue of how to would be great.
    And again you rock this is a really great Jquery, keep it up!

  65. Bee says:

    OOps. didn’t see there were jpg’s so obviously just changing them to png’s makes it happen ;P

  66. sajan kota says:

    Thanks for sharing, very very useful.

  67. cuaryos says:

    Great tuto. you like a real guru. good luck

  68. Webomatik says:

    Superbe
    Merci pour le tutorial

  69. Масса хороших впечатлений!!!

  70. WebDev says:

    Actually I’d like to thank you for this nice tutorial :) It’s amazing, and it’s JS only, no complicated flash needed or something.

  71. good code thanks

  72. Smark says:

    Думаю, недурная работа

  73. axskidkbdy says:

    Чего и следовало ожидать, хозяин сайта грамотно написал.

  74. hemoroid says:

    useful code.

  75. mrityunjay Kamakar says:

    Hi,

    Thanks for your effort . But if u test in IE6 is not working property. Please fix It . It will be great for us..
    Thanks

  76. red pepper says:

    Shared Create a Realistic Hover Effect With jQuery « Blog and Web Design Portfolio of Adrian Pelletier.

  77. motif says:

    Uvvv.It’s really amazing… Thank you very much…

  78. sahayarex says:

    I am very impressed.. thank you so much man….

  79. Adam Cooper says:

    I love your tutorials. Keep it up.

  80. Adam Cooper says:

    This is a really cool effect. Thanks for sharing.

  81. red pepper says:

    Thanks for text. very good

  82. Surge says:

    Great code, thanks for the post.

  83. Good tutorial, nice effect. Thanks!

  84. nice design, thanks for codes.

  85. Oyunlar says:

    Very nice idea, can be applied easily to projects.

  86. Jorge says:

    Well DONE!!!
    Congrats!!! =)

  87. Samar says:

    I was wondering if we could combine the effects into one so that the icons have both refection + shadow and look like to be floating on shiny suface where it reflects :) :)
    BTW Its awesome !!! Thanks

  88. Thanks this is amazing

  89. bayu idham says:

    awesome effect !!

  90. Mr tom says:

    I can’t see!

  91. Simona says:

    Excellent tutorial! If you want to see menus, web site trends, galleries, free extension and job for freelancers etc, visit http://www.1artmedia.com , you have online demo and free download. Bye!

  92. sunil kumar patro says:

    nice shadow and animation

  93. Fabio says:

    You can have support in ie6 the demo you posted?

  94. No dudo de que es un código que ayuda hacer tan real y entretenida una web, de seguro que un buen aporte para le gente interesada en el tema.

    Saludos….

  95. hari prabhas says:

    Thanks for sharing.. its easy to customize

  96. Like the style of this nav! One question, is it possible to float te title of the page beneath this blocks?

  97. Ioan says:

    Great stuff mate was looking this for a long a time :)

  98. Ioan says:

    I have to ask how are these going to work on the ipad and the iphone because sometimes javascript works kinda dodgy on the apple platform, any idea?

  99. Lou says:

    I loved the demo and am trying to utilize it. Working on a new front page for the website. I am only using the shadow version. We have 3 large blocks of graphics/info sitting over a background graphic. They are 225×240. I’ve made all of the necessary adjustments, except one. I cannot get the shadow to sit under the new sized blocks. I resized it to 220 x 27, but it stays behind the graphic. I’ve gone into the CSS and changed :

    #nav-shadow li img.shadow {
    bottom: 0; }
    to
    bottom: 20; }

    This allows me to see the shadow OK, but when I mouse over it, the shadow moves up 20px back to 0 with the block. Any suggestions?

  100. Sam Fleming says:

    Love the implementation of the shadow!

Trackbacks for this post

  1. Create a Realistic Hover Effect With jQuery « Blog and Web Design Portfolio of Adrian Pelletier « Netcrema - creme de la social news via digg + delicious + stumpleupon + reddit
  2. A collection of stuff » Blog Archive » Como crear un efecto de cuadros voladores con jQuery – vía @_krees
  3. popurls.com // popular today
  4. Create a Realistic Hover Effect With jQuery « Blog and Web Design Portfolio of Adrian Pelletier
  5. Create a Realistic Hover Effect With jQuery « Blog and Web Design Portfolio of Adrian Pelletier | Squico
  6. » [j-Query]画像が浮き上がるアニメーションするプラグイン「Hover Effect」|ウェブデザインブログ|graphix-design.jp|
  7. Benjamin A. Shelton | Blog » Blog Archive » Links of the Week: July 15th
  8. Animate en jQuery
  9. javascript library @inforz - アイコン hoverエフェクト
  10. Elsewhere, on August 12th - Once a nomad, always a nomad
  11. 25+ jQuery Tutorials Roundup | ExtraTuts
  12. Amazing Multi Style Menu w/ jQuery and CSS | Free Share Everything
  13. シンプルかつ高機能な jQuery を使ったプラグインのまとめ | Nutspress
  14. Efeito jQuery para Reflexos e Sombras | Webgrafismo
  15. AMB Album » How To Create a Realistic Hover Effect with jQuery
  16. How To Create a Realistic Hover Effect with jQuery - Iconlandia
  17. Efecto hover con jQuery — Tablosign
  18. links for 2009-09-11 « Giri’s Blogmarks
  19. Comment faire pour créer un effet réaliste Hover avec jQuery | Guppytrucs Freeware
  20. BrianLang.ca » Blog Archive » links for 2009-09-12
  21. jQuery Based Hover Effect | PHP and MySQL Development
  22. Un superbe effet de survol avec jQuery | Display:inline
  23. Nilesh Manohar & Erzsebet Marothi » How To Create a Realistic Hover Effect with jQuery
  24. jQuery: tutoriales y recursos para nuestros diseños web | Recursos para desarrollo y diseño web - AlmacenPlantillasWeb Blog
  25. jean philippe gousse » Blog Archive » Create a Realistic Hover Effect With jQuery
  26. jQuery Tutorial – Create a Realistic Hover Effect With jQuery | jQuery Wisdom
  27. links for 2009-09-28 | Yostivanich
  28. Create a Realistic Hover Effect With jQuery
  29. 10 Awesome Techniques and Examples of Animation with jQuery
  30. 10 Awesome Techniques and Examples of Animation with jQuery - Web Design and SEO Blog
  31. 10 примеров анимации с jQuery | Превосходный журнал
  32. CyberHades » Blog Archive » 10 Técnicas impresionantes y ejemplos de animación con jQuery
  33. Jquery ile hazırlanmış 10 adet animasyon ve eğitimi | Blog GizliKale Güncel Linkler
  34. jQuery Tutorial – Create a Realistic Hover Effect With jQuery | jQuery Wisdom
  35. 10 Awesome Techniques and Examples of Animation with jQuery | Seventy Seven
  36. Görenlere “OHA” Dedirten, JQuery ile Hazırlanmış, 10 Adet Animasyon ve Eğitimi « Bay Bedava – Netten Başlıklar
  37. 10 Excellent Animation Tips with jQuery | Amazing and Inspiring Design
  38. 10 Awesome Techniques and Examples of Animation with jQuery « Blogoholics Anonymous
  39. Build a Realistic Hover Effect with jQuery | bijusubhash.com
  40. Görenlere “OHA” Dedirten, JQuery ile Hazırlanmış, 10 Adet Animasyon ve Eğitimi | bildirgin.com | internet, tasarım, popüler kültür, teknoloji, mimler ve mucizeleri
  41. 4:31 ← pseudopost.org
  42. Create a Realistic Hover Effect With jQuery
  43. Ajax Finder [Ajax探索者] » Create a Realistic Hover Effect With jQuery
  44. Diseño Web. Animación con jQuery « Blog de Diseño Web
  45. links for 2009-12-10 | Steve Eller
  46. 13 bài hướng dẫn tạo hiệu ứng cho menu bằng jquery
  47. 10 Awesome Tutorial Animation Using Jquery | denbagus blog
  48. 10 Awesome Animation Using Jquery « Er.Krushna Chandra Muni :: Professional Web Developer | Website Design Orissa | Website Design Bhubaneswar | Website Design India | Website Design New Zealand | Website Design Auckland
  49. DSergio.com – Enlaces de interes #01
  50. สร้างไอคอนสไตล์ mac แบบเทพๆ ด้วย jquery
  51. Create a Realistic Hover Effect With jQuery « 幻岛|领地
  52. Diseño Web. Animación con jQuery | Blog Sevilla Web Profesionales freelance Santuary Servite
  53. Massive jQuery Tutorials And Plugins List – Webexpedition18
  54. Javascript, Ajax links « Comnuoc
  55. Create a Realistic Hover Effect With jQuery :: Web Designer Notes
  56. jQuery buton Uygulamaları
  57. jQuery buton Uygulamaları | hurriyetsondakika.net - Son Dakika, Güncel, Türkiye, Dünya
  58. jQuery buton Uygulamaları « Bay Bedava – Netten Başlıklar
  59. JQuery Bounce on Hover Buttons : Web Designer Ideas – Tutorials, Trends and Ideas
  60. 10 Awesome Techniques and Examples of Animation with jQuery « HUE Designer
  61. Top Worthwhile Tutorials of the Week – #4 | AEXT.NET
  62. Meest voorkomende fouten bij nieuwe ontwerpen @ Chapitre Deux
  63. links for 2010-03-29 » 4exp.net
  64. How to Create Realistic Hover Effect Using JQuery | PHP Ocean
  65. Realistic shadow effect on mouse hover with jQuery « twoGiants
  66. 150个JS特效脚本 - 两天
  67. 150个JS特效脚本☆两天
  68. 10 schöne jQuery Plugins | Webdesgin
  69. 35 jQuery Animation Tutorials | iPixel Creative | Singapore Web Design & CMS Development Company Blog
  70. 35 jQuery Animation Tutorials » abdie.web.id
  71. 35 Tutoriales de animación con jQuery | Valiomadres
  72. 9 Really Cool jQuery Animation Tutorials « Ian Brennan – Design and Development
  73. 35 jQuery Animation Tutorials
  74. بیش از ۳۰ خود آموز عالی در زمینه حرکت و انیمیشن در جی کوئری | ايروني ها
  75. travel around world » 35 jQuery Animation Tutorials
  76. 20 Must Learn Button Tutorials in jQuery and CSS | blueblots.com
  77. 30 Adet jQuery Animation Script(Tutorials) | ilkaymola.com
  78. jQueryいろいろ « Webデザイン ホームページ制作 名古屋 豊橋 | creal クレアル
  79. Tara Jane Irvine » Blog Archive » Inspiration
  80. マウスオーバーの新たな見せ方 - BlackFlag
  81. @studio – tell your story with clarity (Corporate) | Zip Bucket : Graphics, Code, Video ,Audio, 3d Downloads
  82. Seth Wright » Blog Archive » Five useful jQuery elements
  83. daubsters.com » Blog Archive » Daubsters.com Has Finally Launched!
  84. Create Smooth Hover animation effect With jQuery | webtrendset
  85. Animated Call to Action Button – Butonlarınıza kararma efekti « En güzel ve kullanışlı JQuery Uygulamaları
  86. 25个 jQuery 实例教程 | 高品质 HTML+CSS 制作服务 - SonicHTML
  87. 20+ fresh jQuery Animation Tutorials | Free Resources for Designers & Developers
  88. jQuery |BobのWordPress企業サイト
  89. 35 jQuery Animate Tutorials | webdesign14.com
  90. How To Create a Realistic Hover Effect like jQuery Animate Effect | jquery plugins
  91. Don't Miss New 25+ jQuery Tutorials | Webblog360
  92. Webデザイン ホームページ制作 名古屋 豊橋 | creal クレアル - 画像を使ったjQueryプラグイン

Comments are now closed for this article.