Create a Thumbnail Gallery with Slick Heading and Caption Effect with jQuery

Create a Thumbnail Gallery with Slick Heading and Caption Effect with jQuery


Create a Thumbnail Gallery with Slick Heading and Caption Effect with jQuery

Introduction

This is a simple jQuery tutorial, but can be extremely useful in frontend design. It's an elegant way to put more content in your website, but only display it when the user wants to see it. It keeps your website clean, but in the same time does not compromise your website content.

You can check out the demonstration and the code. :) enjoy.

1. HTML

It's simple, inside the container - photo class you have three objects, first div is the heading, image in the middle and last div is the caption. You can put links, rating whatever you like inside it.

<div class="photo">
	<div class="heading"><span>Pier</span></div>
	<img src="images/pier1.jpg" width="300" height="186" alt="" />
	<div class="caption"><span>Lorem de scua shemf huan rougt ecrit vato de souju kanasa.</span></div>
</div>

2. CSS

One thing you have to know about the CSS is, if you want to position objects within a container, the container must have relative position and the object must have absolute position too. In this case, photo class is the container, heading and caption classes are the objects with absolute position.

So, it's easy, by default, heading and caption classes are hidden with top (heading) set to -50px (the height of the heading) and same thing to caption, but instead of top, it's bottom.

I have shared this CSS tips in my 15+ CSS Tips and Tricks posts

	.photo {
		/* relative position, so that objects in it can be positioned inside this container */
		position:relative;
		font-family:arial;	
		
		/* hide those extra height that goes beyong the size of this container */
		overflow:hidden;
		border:5px solid #000;
		width:300px;
		height:186px;
	}	
	
		.photo .heading, .photo .caption {
			/* position inside the container */
			position:absolute;
			background:#000;
			height:50px;
			width:300px;
			
			/* transparency for different browsers */
			/* i have shared this in my CSS tips post too */
			opacity:0.6;
			filter:alpha(opacity=60);  
		     -moz-opacity:0.6;    
			-khtml-opacity: 0.6;  

		}
		
		.photo .heading { 
			
			/* hide it with negative value */
			/* it's the height of heading class */
			top:-50px;
		}

		.photo .caption { 		
			/* hide it with negative value */
			/* it's the height of bottom class */
			bottom:-50px;		
		}
		

		/* styling of the classes*/
		.photo .heading span {

			color:#26c3e5;	
			top:-50px;
			font-weight:bold;
			display:block;
			padding:5px 0 0 10px;
		}
		
		.photo .caption span{
			color:#999;	
			font-size:9px;
			display:block;
			padding:5px 10px 0 10px;
		}

3. Javascript

Javascript is pretty straight forward, just display the div and hide the div, the only difference between the heading and caption is, the css properties (top and bottom), I added the easing as well to give your more option in choosing the right transition for your image thumbnail gallery.

	
	$(document).ready(function () {

		// transition effect
		style = 'easeOutQuart';

		// if the mouse hover the image
		$('.photo').hover(
			function() {
				//display heading and caption
				$(this).children('div:first').stop(false,true).animate({top:0},{duration:200, easing: style});
				$(this).children('div:last').stop(false,true).animate({bottom:0},{duration:200, easing: style});
			},

			function() {
				//hide heading and caption
				$(this).children('div:first').stop(false,true).animate({top:-50},{duration:200, easing: style});
				$(this).children('div:last').stop(false,true).animate({bottom:-50},{duration:200, easing: style});
			}
		);

	});

Conclusion

This is a simple jQuery tutorial, but can be extremely useful in frontend design. It's an elegant way to put more content on your website, but only display it when the user want it. It keeps your website clean, but in the same time provide all the information to your visitors.

Last but not least, I need your support :) If you like this article, please help me to promote it by adding this post to your bookmark, subscribe to my RSS for more jQuery tutorial and design inspiration posts! AND also, you can BUY ME A DRINK (link in the footer) to motivate me and keep me awake! Thanks!

Author: Kevin Liew

Kevin Liew is a web designer and developer and keen on contributing to the web development industry. He loves frontend development and absolutely amazed by jQuery. Feel free to say hi to me, or follow @quenesswebblog on twitter.

Share the love

50 comments

kevin Admin
Tue, 4th August 2009
Hi Jo, thanks very much for the amendment! really appreciate it! Will remember the rapid fire problem in my future tutorial! Reply
Alexander Bickov
Tue, 4th August 2009
Nice post for my developers :) Reply
FireDart
Tue, 4th August 2009
Been looking for something like this. Reply
Hezi
Tue, 4th August 2009
it ROCKS! Reply
Jo
Tue, 4th August 2009
Great but you can modify your javascript for :

$('.photo').hover(
function() {
//display heading and caption
$(this).children('div:first').stop(false,true).animate({top:0},{duration:200, easing: style});
$(this).children('div:last').stop(false,true).animate({bottom:0},{duration:200, easing: style});
},

function() {
//hide heading and caption
$(this).children('div:first').stop(false,true).animate({top:-50},{duration:200, easing: style});
$(this).children('div:last').stop(false,true).animate({bottom:-50},{duration:200, easing: style});
}
);
Also, you fix the rapid movement of the mouse Reply
cri
Wed, 5th August 2009
Great but doesn't work in internet explorer 7 Reply
viswanath
Fri, 7th August 2009
thank u very much..! Reply
tosin
Fri, 7th August 2009
The other text at the bottom is not showing in the evil browser - I.E 7 Reply
kevin Admin
Tue, 11th August 2009
Hi Wink! Thanks a lot! :) Legendary!

@Jeff, you need to set the top and bottom of the heading and excerpt to 0 and ignore the rest of the javascript. :) Reply
wink
Tue, 11th August 2009
The IE7 problem can be fixed by adding left:0px; to the caption class.
(so .photo .caption { bottom:-50px; left:0px; } Reply
jeff
Tue, 11th August 2009
HI;
great script !. I would like the caption to be visible at all times , any advise ?

tks Reply
jack rudo
Wed, 12th August 2009
great post. I would love to have this included as part of a layout with rows / cols and paging. Have you developed this further?

Thanks Reply
wink
Wed, 12th August 2009
Hey Kevin, no problem, glad I could help :) Reply
kevin Admin
Wed, 12th August 2009
@jack, yes, you just have to duplicate the html and replace it with different image, heading and caption. It will work! Reply
kevin Admin
Wed, 12th August 2009
Hi guntars, it tested on firefox, safari, chrome, ie6, ie7 and should work on ie8 as well. (creadit to Wink for solving ie problem) Reply
guntars
Wed, 12th August 2009
hi, my IE7 not showing transparent heading/caption backgrounds. Is it up to my pc or not? Reply
guntars
Thu, 13th August 2009
hi again, well the backgrounds are showing, but they are not transparent. Maybe its connected with DXImageTransform.Microsoft.AlphaImageLoader ? Reply
marklee
Tue, 18th August 2009
Thanks for the links and all informative stuff you provided.
Reply
kevin Admin
Wed, 19th August 2009
@guntars, what browser are you using? Reply
Sympa
Thu, 24th September 2009
Hello! first off amazing job! I love this! Second. I am having a problem using multiple image sizes with this script. How would I be able to redefine the script to a second image size so that both will load? See link for example.

http://sympa-inspir.com/symtest Reply
kevin Admin
Thu, 24th September 2009
@Sympa: Nice clean design! I think, you will have to declare a new set of CSS, duplicate the css and change .photo to .photo2 (other name).. and then, in the jquery script change

$(\'.photo\')....

to

$(\'.photo, .photo2\')....

hvnt\'t tested it, but I think it will work. :) Reply
Sympa
Thu, 24th September 2009
You are an absolute genius. Expect an article at length about you site as soon as my own blog is up and running. Much much love.

-Sympa Reply
Sympa
Thu, 24th September 2009
Just an update showing a working version of the script with two differing image sizes.

http://sympa-inspir.com/symtest Reply
David
Fri, 2nd October 2009
Just wanted to say thx. so much for the detailed tutorial. It was very easy to implement into our website. Keep up the great work! Reply
designzzz
Wed, 14th October 2009
very well done !! love it and will definately use it Reply
tuna
Tue, 10th November 2009
it\'s amazing.. Reply
Carlos
Thu, 14th January 2010
Thanks for the amazing tutorial once again! i´ve just a "noob" problem i guess, i can´t make it work when i change the isolated css to an external sheet. any ideas? Reply
Carlos
Thu, 14th January 2010
wrong comment link :s I´m sorry, i was trying to comment this link instead http://www.queness.com/post/443/jquery-image-gallerynews-slider-with-caption-tutorial. Reply
Daniel
Fri, 15th January 2010
Nice. Thanks for the script. Reply
Shelley
Mon, 25th January 2010
where do I put the java? Reply
lin
Tue, 9th February 2010
very good effect.
i like very much. Reply
Liam
Fri, 19th March 2010
Love it. I really need one thing though - is there a way to reset the timer back to 5 seconds (or whatever it's set as) when you click on a next/previous button? Currently it is a bit annoying to browse through the slides, as every 5 seconds it skips forward regardless. Reply
kevin Admin
Sun, 21st March 2010
Hi Liam, I don't get what you mean. It's not a slideshow and it doesn't have next/previous buttons. Reply
daniel
Fri, 26th March 2010
wery cool cant wait to use it Reply
pratham dutta
Sun, 28th March 2010
Hi I am web designer can anyone send me a javascript image slider tutorials with next previous buttons

http://www.scrapsforever.com Reply
daniel
Tue, 30th March 2010
I have noticed that IE8 doesn't suport transparency on mouse hover like firefox..
to bad realy... any way I'm using it for my portfolio :) realy cool! Reply
Sergio Martos
Thu, 8th April 2010
Hi, thanks for the amazing tutorial… I really need one thing though: is possible add rounded corners in this tutorial? Thank you very much..! Reply
kevin Admin
Mon, 21st June 2010
@Sergio: you can use the css3 for the rounded border, or you have to make a rounded border images.

@Francesco: hey francesco, unfortunately, this isn't a slideshow, just an effect that you can apply to thumbnail :) Reply
Francesco
Mon, 21st June 2010
Very useful script! But what if I need to avoid the images' rewind? I'd like to see the first photo as a continuos slideshow.
Thanks for helping! Reply
tokat nakliyat
Wed, 18th August 2010
good code thanx Reply
Guerilla Grafix
Mon, 27th September 2010
Hey, Great Tutoria! Is there a way that I could incorporate this with HuddleTogehter's Light box scripts? I am new to jQuery and scripts, but your tuts have helped me come along way. However, I am stuck on incorporating the two scripts.
Thnx.
Nigel aka Ape Reply
Jim
Tue, 25th January 2011
Great script. Works in Firefox and IE 8. On the MAC I cant seem to get it to work on Safari and Chrome. Any ideas? Reply
Kevin Liew Admin
Wed, 26th January 2011
Hi Jim, I have tested in on Mac chrome and safari. In fact, this was built under mac environment. It works. Does the demo work for you? Reply
Hans
Fri, 11th February 2011
How can i make, that the hovering effect starts after one second? Only on hovering! Reply
Kevin Liew Admin
Fri, 11th February 2011
ThereseStewart
Sat, 24th December 2011
Every body acknowledges that men's life seems to be expensive, nevertheless different people need money for different things and not every man gets big sums cash. Thus to receive quick <a href="http://goodfinance-blog.com ">loan</a> or secured loan would be a correct way out. Reply
toprak
Mon, 20th February 2012
hi !!! how to make a bottom-up ? Reply
shakir
Mon, 26th March 2012
How can i make, the slider circular . Reply
Curtis
Mon, 16th April 2012
Great script. If the transition easing effect isn't working is it possible it's due to a conflicting script I am already using? Reply
Kevin Liew Admin
Tue, 8th May 2012
Did it show any error in the console? Reply

Leave a Comment

Please keep in mind that comments are moderated and rel="nofollow" is in use. You can use [code][/code] if you want to write codes. Don't spam us :) Thanks!

Advertisement