Zoom-Info – How To Create An Informative Image Gallery With jQuery & CSS
Question: Have you ever wanted to neatly display a few lines of text about an image in your site but didn’t want to compromise on the design of your overall layout? In today’s post I’m going to show you how to create a useful information-rich jQuery Image Gallery that solves that problem. The best part of it is that it’s so simple to write up that all you’ll need are jQuery’s excellent .hover() and .animate() functions to get it up and running.
You can view a live MTV themed demo of what we’re going to create here or see the screenshot below.
(Click the image above to view full-size version)
In User-Interface design we’re always trying to push the envelope with new and interesting ways of presenting interfaces that users are used to seeing. One such interface is the traditional image gallery. You can find them pretty much everywhere..social networks, shopping, e-commerce ..even porn (not that I would ever dream of looking at anything like that!). The question is.. how do you allow a user to still get all the information they want without having to sacrifice on your UI or design?. The answer, is by hiding that information in your interface, but keeping it accessible.
Let’s take a look at the following wirefame for today’s jQuery component.
What we’re going to try achieving is having our full-size gallery image occupy the entire area of the wire-frame in our default view (“A”). What the user doesn’t know is that the image is actually contained in a div with more information about it (which you can see in the area denoted by “Header” and “Text goes here”).
When the user hovers over this image we’re going to animate/resize it to occupy the thumbnail space (“B”) you see above. This will allow the user to view all the information they want about it. They can then return back just by moving their cursor outside of the image pane.
Now that we know what we’re building, let’s code it up!.
HTML for the gallery:
![]()
Taylor Swift
Taylor Alison Swift (born December 13, 1989) is an American country pop singer-songwriter and actress.![]()
Rihanna
Rihanna (born February 20, 1988) is a Barbadian R&B recording artist and model born in Saint Michael, Barbados.![]()
Black Eyed Peas
The Black Eyed Peas is a Grammy Award winning hip hop group that formed in Los Angeles, California in 1995.![]()
Lady Antebellum
Lady Antebellum is an American country music group formed in Nashville, Tennessee in 2006.![]()
Lady Gaga
Lady Gaga is an American recording artist who rose to fame with her first two singles "Just Dance" and "Poker Face".![]()
The Killers
The Killers is an American rock band from Las Vegas, Nevada, formed in 2002 who have sold over 16 million records worldwide.
CSS:
.galleryContainer
{
width: 1024px;
}
.galleryImage {
background-color:black;
width:325px;
height:260px;
overflow:hidden;
margin:5px;
float:left;
}
.info{
margin-left:10px;
font-family:arial;
padding:3px;
}
.info h2{
color:gray;
}
.info p {
color:white
}
.clear {
clear:both;
margin-top:10px;
}
jQuery:
$(document).ready(function()
{
$('.galleryImage').hover(
function()
{
$(this).find('img').animate(
{ width:100,
marginTop:10,
marginLeft:10
}, 500);
},
function()
{
$(this).find('img').animate(
{width:325,
marginTop:0,
marginLeft:0
},300);
});
});
and that’s it!. By using jQuery’s always-useful animate() and hover() functions we’re able to define simple behaviours that shrink the size of the overall image and re-position it for more information to be visible.
You can now download the source files or view the demo to see what we’ve created.
Why do I think this is a better solution, than say, something that just moves the image completely off-screen?. Well, It’s really a question of context.
If you’re reading about a particular topic, no matter how short he piece of text on it is, allowing the user to retain the context of that text (in this case the image in thumbnail form) lets them to easily remember why they hovered over it or what took their interest.
This is probably more important in interfaces where you’re clicking through to see more images, like a Facebook Photo Album – eg. just because that folder cover has a fun picture on it doesn’t mean the rest of it’s contents are!. Thats where a descriptive caption comes in handy and why I think this isn’t a bad idea for a user interface.
I hope you found this article useful!. If so, please feel free to share or leave a comment below. Thanks!
-Addy.
31 Comments
[...] }admin Read Post Question: Have you ever wanted to neatly display a few lines of text about an image in your site [...]
nice effect, so smooth
thanks for share ^_^'
love it!
Love it!!
Very nice! Thanks.
You're welcome! I'm very glad you liked it.
Thank you arvind!
No problem! I hope it comes in useful
Man u are big!! It's nice very nice love u tuts
I will re tweet this … do more link u on my blog. It's great more tuts from u !!
Regards
From Poland
I'm happy to hear you like the tutorials!
Thanks for the re-tweet and mentions. I appreciate them
Really a nice one! Very usable! Thanx!!
You're very welcome, Kristel.
Great demo and tutorial, thanks for posting it. I have a question though. I'm trying to implement this but the source images aren't all the same dimensions. The overflow: hidden works well for this but after hovering over and then removing the mouse the image returns to proportions for the original image and not how it appeared before the mouseover so as a result some images show part of the text underneath. Do you have any suggestions for this? Thanks again for the great tutorial.
Hi Mike. I'm glad to hear the tutorial was useful.
Correct me if I've understood what you're trying to achieve, but effectively you're trying to use this effect with a set of source images that aren't all the same size and thats resulting in a few quirks with the way the animated effects work.
What I would probably do in that case is one of a few different things. You've mentioned trying to use overflow:hidden, but how about having each of the of the images appear as the background-image property of a set of div's? This effect works best if you set a frame size for the overall image that you want to target. You can then set each of the div's to have an appropriately positioned background-image and because you're not trying to resize the differently sized images, just the same sized divs, you should be able to achieve the effect you're after.
I hope that helps!
Thanks for the reply Addy. I'll give your suggestion a shot this afternoon and post back how it goes and an example if it works out. Thanks again.
[...] Website: http://addyosmani.com/blog/image-gallery [...]
very amazing customization jQuery image gallery, testing it, working fine
Thanks, Ryan. I'm glad you like it!
You may want to add .stop() before the animate function to avoid the repeated animation when you hover the image more than 2 times
<pre>
$(this).find('img').animate
</pre>
Sorry – $(this).find('img').stop().animate
[...] Zoom-Info – How To Create An Informative Image Gallery With jQuery & CSS | AddyOsmani.com | W… [...]
[...] Fuente | Addy Osmani [...]
[...] Zoom-Info es una forma de presentar imágenes acompañadas de texto de una forma dinámica y muy visual. [...]
[...] voglio segnalarvi un’ottima galleria informativa creata dall’amico Addy con jQuery e CSS da utilizzare liberamente per i nostri progetti [...]
Great man, love it…kepp it up…ver well explained…
Thank you!
Well this is great. thanks for all the good stuff. Jquery is the best.
I love it thank's
thanks from Holland
[...] Ver Demo – Descarga – Mas info Zoom-Info [...]
good work budy… seems to be a good example
nice work
include in just 3 minutes
[...] Demo Download [...]