Build Internet has a brand new theme, and that's only the beginning. Read the full story or hide this bar

Sproing! – Make An Elastic Thumbnail Menu

Sproing! – Make An Elastic Thumbnail Menu

In an ongoing attempt to offer alternative methods to spruce up menus, I’ve pieced together an elastic thumbnail menu.

What does it do exactly?

  • Magnifies menu items when they are hovered over.
  • Menu items expand upwards.
  • View the demo to see it in action.

Hopefully you know what you’re getting into, let’s make this thing happen.

The HTML

Quick and easy, the general framework we’ll be using goes as follows:

<div id="menuwrapper">
	<div id="menu">
		<a href="#" class="menuitem"><img src="image.jpg"></a><!--Template for each menu item-->
	</div>
</div>

The CSS

Normally when a div tag has to expand to accommodate more content, it does so downwards, adding height onto the bottom of the element rather than the top. For this menu we will want to do the exact opposite – when the user hovers over the thumbnail it should expand upward (think about how the OSX dock works).

We’re going to go about this by making use of position:fixed, which essentially lets us “fix” elements to the bottom. Let’s break down the elements.

/* The container which the menu is "locked" to the bottom of */
#menuwrapper{ position:relative; height:210px; }

/* Fixes the whole menu to the bottom of the parent div */
#menu{position:absolute; bottom:0;}

/* Each individual menu item fixed to the bottom with display:inline-block to create elasticity */
.menuitem{ position:fixed relative; bottom:0px; display:inline-block; }

The jQuery

The jQuery in my example serves two purposes:

  1. Resize images to smaller sizes when page first loads.
  2. Animate images to larger size when hovered over.

Here’s the snippet that makes this all happen (With inline comments for explanations):

$(document).ready(function(){
	$('.menuitem img').animate({width: 100}, 0); //Set all menu items to smaller size

	$('.menuitem').mouseover(function(){ //When mouse over menu item

		gridimage = $(this).find('img'); //Define target as a variable
		gridimage.stop().animate({width: 200}, 150); //Animate image expanding to original size

	}).mouseout(function(){ //When mouse no longer over menu item

		gridimage.stop().animate({width: 100}, 150); //Animate image back to smaller size

	});
});

Internet Explorer Image Scaling Fix

This has been brought to attention before, but when it comes to resizing images, Internet Explorer won’t do a good job unless you add the follow line into your css:

img { -ms-interpolation-mode: bicubic; }

After taking care of that fix, your menu is ready to roll, nicely done.

Wordpress.com stats not installed! Posted Monday, September 21st, 2009 / Back to Top

I this post. Tweet
SPONSOR

86 Comments 140 Mentions

  1. Tim Smith Author Editor

    Awesome effect guys! I’m trying to get more into web design and this really helps. Thx ;-)

    September 21, 2009 · Reply

  2. Evan Jones Author Editor

    Haha sweet!

    September 21, 2009 · Reply

  3. Rilwis Author Editor

    This effect is cool and easy to do. Cool, i love your tutorial. But it’s better when you display the menu items as unordered list as usual.

    September 21, 2009 · Reply

  4. Callum Chapman Author Editor

    Great effect, might use that one day :)
    .-= Callum Chapman´s last blog ..The Circlebox Monthly: 18th September 2009 =-.

    September 21, 2009 · Reply

  5. brian Author Editor

    you guys know what you are talking about. very cool

    September 21, 2009 · Reply

  6. Alex Author Editor

    Great tutorial, love the demo. Keep up the good work
    .-= Alex´s last blog ..How to set up a hotel reservation form in a WordPress page =-.

    September 21, 2009 · Reply

  7. AskTheBigO Author Editor

    Great effect. Now it needs .focus adding for those who can’t use a mouse but still need to see which link they are focussed on.

    September 21, 2009 · Reply

  8. memowe Author Editor

    Nice. You can use the .hover shorthand for .mouseover and .mouseout.

    September 21, 2009 · Reply

  9. Christian Author Editor

    It doesn’t work with IE…I hate IE…but really cool effect

    September 21, 2009 · Reply

  10. Ted Goas Author Editor

    Wow, that is not a lot of code to get that effect! Nice!

    September 21, 2009 · Reply

  11. Sam Dunn Author Editor

    @Christian
    Thanks for pointing that out, I fixed it up. I should have used display:inline-block rather than display:inline-table. I’ve updated the download/demo

    September 21, 2009 · Reply

  12. taquito Author Editor

    nice effect, maybe i can use it in my blog :)
    .-= taquito´s last blog ..Virtua Tennis 2009 [Full | Multi-Esp.100%] =-.

    September 21, 2009 · Reply

  13. Ivan Mišić Author Editor

    Wooow, nice one, just like Ted sad, not a lot of code for that great effect
    .-= Ivan Mišić´s last blog ..Prvi koraci nakon instalacije WordPressa =-.

    September 22, 2009 · Reply

  14. CertPal Author Editor

    Nicely done. Reminds me of a mac OS like toolbar plugin I saw a while back.

    Since you are allowing people to download the code and posting snippets, you should accompany that with a license, so developers know what is allowed and what is not.

    Thanks for sharing
    .-= CertPal´s last blog ..Response: Are Naming Conventions Still Needed For Abstract Classes? =-.

    September 22, 2009 · Reply

  15. Yasmin Lawsuit Author Editor

    The demo is great. This is a really cool effect. Nice Work.
    .-= Yasmin Lawsuit´s last blog ..Birth Control Linked to Medical Problems =-.

    September 22, 2009 · Reply

  16. Jason Author Editor

    Nice!
    .-= Jason´s last blog ..How to Create an Ajax Style File Uploader =-.

    September 22, 2009 · Reply

  17. Soph – - Author Editor

    Hey; do you think this would work with text? If so, how would I do that?

    September 23, 2009 · Reply

  18. Flex developer Author Editor

    Your site is very good. There are useful information and most importantly, for sharing great. Thank you ….

    September 25, 2009 · Reply

  19. Kathryn Author Editor

    Great idea – but when I tried the demo in Firefox, all the menus sprung up and aligned vertically! Is it supposed to do that?

    September 26, 2009 · Reply

  20. Jad Graphics Author Editor

    Cool effect. Thanks for sharing this. I really love your site, especially how much great content you already have for a young site.
    .-= Jad Graphics´s last blog ..Outer Space Text Effect =-.

    October 3, 2009 · Reply

  21. Richie Author Editor

    The effect is kickass. But unlike in the demo, the images align vertically and the effect screws up.
    And the position parameter has no effect on the sproing, whether it is absolute or fixed :(
    .-= Richie´s last blog ..Inspiration #1 : What does it take to become a dedicated artist? =-.

    October 7, 2009 · Reply

  22. C Author Editor

    I liek the tutorial. How could I make the last button go only to the left like the first button goes to the right?

    October 13, 2009 · Reply

  23. Chris Pierre Author Editor

    Another Great Tut!
    I will have to try this out ASAP!

    October 14, 2009 · Reply

  24. Teet Author Editor

    it gives error on (“.menuitem img”) http://www.alpinacolor.ee/tooted

    October 25, 2009 · Reply

  25. Евгений Author Editor

    Please tell that for a font on this picture?
    http://buildinternet.com/live/elasticthumbs/officeal.jpg

    In advance many thanks

    December 3, 2009 · Reply

  26. wespai Author Editor

    thx collect it to ajax.wespai.com

    December 25, 2009 · Reply

  27. abdullah alaydrus Author Editor

    cool effect

    will try to use it, thanx dude

    January 13, 2010 · Reply

  28. Jonathan Foucher Author Editor

    Pretty god but that’s been done about 3.8 million times already… I’m by no means an expert at CSS or javascript but I developped the exact same same thing on my blog about 1 year ago.
    What would have been interesting, although not a new implementation either, is that the images on each side of the one being hovered would grow as well, by something like half the amount…

    January 15, 2010 · Reply

  29. Muxx Author Editor

    Going to have so much fun playing around with this in a new project. I want to combine this effect with a few AJAX scripts to create a site that almost acts as a UI from an OS.

    March 12, 2010 · Reply

  30. Hiep Author Editor

    This tutorial is really damn beautiful. Nice code!

    May 5, 2010 · Reply

  31. Mouad Author Editor

    Thank you. I know where to put the CSS code, but I dont know (beginner here) where to add that html code and especially the jquery code. Should I add the latter to a new file and name it *.js ?

    Thanx

    May 7, 2010 · Reply

  32. donna Author Editor

    so, how do i integrate this into wordpress?

    May 21, 2010 · Reply

  33. sivaranjan Author Editor

    Your website is incredibly beautiful and useful. I have taken liberty to add this article to my CSS aggregator site. I hope you wont mind that.

    May 24, 2010 · Reply

  34. Rob Author Editor

    We are testing this on our works website as the IT department get jobbed for this role. Works great but in Firefox it goes wild have you any ideas.

    June 18, 2010 · Reply

  35. 123doing Author Editor

    It’s very good.
    I like this.
    Thanks for share.
    And I wrote something to introduce this project for my readers.
    You can find the post about this in my website.
    If something is wrong,pls figure it out.thanks.

    June 21, 2010 · Reply

  36. galaxark Author Editor

    Great Stuff Thanks!

    July 16, 2010 · Reply

  37. befashionlike the fashion blog Author Editor

    Thanks for this great tutorial, how can i use it for “related post” on wordpress ?
    my email befashionlike@gmail.com

    July 22, 2010 · Reply

  38. Dann Author Editor

    How can i do if i want change the width by percent and not by px??

    July 22, 2010 · Reply

  39. James Author Editor

    Hey wicked effect, what if you have like 20+ images you want to apply this to, but want it to fit within an 800px width div, is there a way to automatically scroll left and right once a user gets towards either side?

    July 23, 2010 · Reply

  40. Nutaryuk Author Editor

    I’m a beginner in blogging.
    This is a great tips for my blog.
    Thank you very much.

    July 31, 2010 · Reply

  41. Kibal4iw Author Editor

    that this is for bottombottom:0; in css, please be careful.

    August 1, 2010 · Reply

  42. Abdullah Author Editor

    just what ive been looking for the past few weeks!!
    nice work guys

    August 15, 2010 · Reply

  43. BB Author Editor

    Nice one. Its innovative and cool!

    August 24, 2010 · Reply

  44. offday Author Editor

    Awesome effect. I was wondering if it is possible to get the effect go down instead of going up?

    August 31, 2010 · Reply

  45. Chichote Author Editor

    Hello.
    I made a modification of the script and add a horizontal menu drop.

    http://chichote.com/2010/simple-menu-dock-desplegable-con-jquery/

    thanks.

    September 27, 2010 · Reply

  46. Adie Author Editor

    Nice work.

    I’m pretty sure the same or similar effect could be created using CSS transform as well.

    October 13, 2010 · Reply

  47. Barkın Author Editor

    Hi . I cant use it in aspx MasterPage.cs file ? Is it for pure HTML only or I do something wrongly. It works in a pure HTML file by the way. Thank you.

    November 25, 2010 · Reply

    • Zach Dunn Author Editor

      There’s no reason that you wouldn’t be able to use this in ASP since JavaScript is client side.

      November 25, 2010 · Reply

      • Barkın Author Editor

        sure it is.. :) The problem is for another javascript .js file is found in the same aspx file. (for another image slider..) Maybe it avoids elastic thumb. menu carousel. Because when I tired to use to get all the above code from another aspx, it’s worked properly. Thank you Zach.

        November 25, 2010 ·

  48. toun Author Editor

    clever! thnx for sharing

    January 8, 2011 · Reply

  49. Stew Author Editor

    Awesome! Nice lightweight interactive menu. Will definitely look into using something like this.

    January 31, 2011 · Reply

  50. John Author Editor

    How do I expand the images starting from bottom right instead of left?

    February 15, 2011 · Reply

  51. Ildi Author Editor

    This is brilliant, just what I’ve been looking for! I copy pasted all the coding (which doesn’t mean an awful lot to me) but must have got something wrong as the images display vertically?? I don’t even know where to look…

    April 15, 2011 · Reply

    • Ildi Author Editor

      Sorry, take no notice of me, talking nonsense…. I’ve just realised that my theme has a #wrapper too and that’s what’s causing the problem! :)

      April 15, 2011 · Reply

    • Cheyanna Author Editor

      Never would have thunk I would find this so inisdpensable.

      July 1, 2011 · Reply

    • diyflkbxr Author Editor

      U3ms0X ardyrnbkkjgv

      July 1, 2011 · Reply

  52. web designing uae Author Editor

    Just love the demo.Thanks for the share.

    June 1, 2011 · Reply

  53. Colchester Website Design Author Editor

    Great work… very simple and effective!!!

    June 8, 2011 · Reply

  54. Dortcelik Cocuk Hastanesi Randevu Alma Author Editor

    Thanks for sharing and keep up the good work. That is a great article.

    June 19, 2011 · Reply

  55. طراحی وب سایت Author Editor

    Thanks for posts

    July 31, 2011 · Reply

  56. KaleidoMatt Author Editor

    A great technique and interaction with such simple code. What’s the best method of centre aligning the menu? Is this possible?

    September 14, 2011 · Reply

  57. Eva Author Editor

    Let’s try! Thank you! :)

    September 14, 2011 · Reply

  58. Paul Author Editor

    Sam,

    Nice job and many thanks. However it only seems to work with jQuery 1.3.1 or older. Is there anything that can be done so that it works with later versions of jQuery?

    October 31, 2011 · Reply

  59. mike Author Editor

    This looks great, but! how about a more indepth tutorial on how it all links together?

    November 18, 2011 · Reply

  60. alovilla Author Editor

    thank you.nice job

    November 23, 2011 · Reply

  61. Colchester Printers Author Editor

    This is great.. Can the Div have any name or is it set?

    December 14, 2011 · Reply

  62. Exphor Author Editor

    How can I get one of the images to stay large, say when that link is active.

    January 29, 2012 · Reply

    • mell Author Editor

      did you find out?

      June 8, 2012 · Reply

  63. Uriah Author Editor

    Quite long, i don’t understand.

    February 21, 2012 · Reply

  64. Farm Gate Author Editor

    rather radical. Even so, I am sorry, because I can not subscribe to your whole plan, all be it refreshing none the less. It would seem to everyone that your commentary are not completely validated and in actuality you are generally yourself not totally certain of the point. In any case I did appreciate examining it.

    March 19, 2012 · Reply

  65. Website Design Author Editor

    Is there a way of of animating like a carousel?

    May 16, 2012 · Reply

  66. rubén Author Editor

    I love it. Theres just one step I don’t know how to do due to my ignorance… The third code, the jQuery one… Do I have to paste it into the code of my page? If so… where in it?

    May 18, 2012 · Reply

  67. Logo EPS Author Editor

    Great tutorial
    one question: how about a more indepth tutorial on how it all links together?

    June 1, 2012 · Reply

  68. Digital Ark Author Editor

    Very good, well designed solution.

    Thank you for sharing.

    Simon

    June 30, 2012 · Reply

  69. Serhat Author Editor

    Thanks for shared.. nice script.

    July 11, 2012 · Reply

  70. kayseri emlak Author Editor

    I love it. Theres just one step I don’t know how to do due to my ignorance

    July 11, 2012 · Reply

  71. kayseri satılık daire Author Editor

    This looks great, but! how about a more indepth tutorial on how it all links together?

    July 11, 2012 · Reply

  72. kayseri kiralik daire Author Editor

    Nice job and many thanks

    July 11, 2012 · Reply

  73. XTC_300 Author Editor

    Hi Sam,

    unfortunatly your code does not work – neither your demo nor my attempt to rebuild it locally at my pc with current jquery 1.8.0 (both tried with firefox browser).

    Do you have any suggestions ?

    August 24, 2012 · Reply

    • Sam Dunn Author Editor

      jQuery 1.8 has been known to cause issues with older scripts – I would check the javascript console for errors if you choose to use this version.

      August 24, 2012 · Reply

  74. Stephen Hannon Author Editor

    I’m new to css ect so is there an in depth tutorial anywhere that I can follow ?

    October 5, 2012 · Reply

  75. Ali Author Editor

    Very good menu and animasyon. Thanks.

    October 17, 2012 · Reply

  76. Drew Author Editor

    Thank you very much for this. For anyone not sure where to place the jquery code, make sure (at least this worked for me) to place it inside the tag within your header.php file for the WordPress users.

    And add this piece of line:

    before:

    if you haven’t yet called to the ‘googlecode…’ library yet

    December 5, 2012 · Reply

  77. Dave Author Editor

    In the sample code you have:

    bottombottom: 0;

    Pretty sure this is a typo, as it’s throwing syntax errors in my editor and I don’t remember any bottombottom attributes ;). I changed it to bottom: 0; and the positioning went to the top of the page, outside the menuwrapper, changing it to 1 brought it back to where it should be under the wrapper. Just in case anyone else is having issues with this part of the css.

    Anyone not sure where to put the jquery, you need to put it in between tags between the tags and after you have loaded the jquery via your link call.

    December 27, 2012 · Reply

  78. Dave Author Editor

    Ok, so I saw some people in the comments asking for a more in depth tutorial, so I did one up real quick to show you how to get this working. As I’m sure the author is busy, and I had the time, it was no big deal for me to knock it out. https://www.youtube.com/watch?v=XyWlL4UYLgk

    December 28, 2012 · Reply

 

Join the Conversation

Back to Top / Comment RSS

2012 Build Internet. Created by One Mighty Roar. Icons by Komodo Media. Back to Top