tutorial

tutorial » jquery-tutorial » Thumbnail image gallery with jquery

Thumbnail image gallery with jquery


16 December 2011 , 10:46 pm

poster-Thumbnail image gallery with jquery

Thumbnail image gallery with jquery is jquery ,html and css based Image gallery.this Image Gallery has image Grid,and when we hover over these images these zoom out like it  happens in Google images.when we click on the image on the thumbnail Image Gallery then that image shows up in higher resolutions on right hand side.the effect I used here for images is the fade in , fade out and fadeto of the jquery when image shows up in high res adjacent to grid.

the Thumbnail Image gallery with jquery will look like the image below:

 

thumbnail image grid

This is how the image Grid will look like. when we will hover on any thumbnail of this image gallery then that thumbnail will zoom oput and further when we click on that thumbnail then that image will show up on right side box in higher resolution.The image will fade on and then out.

so far that looks cool.this is very easy to use and understand.The grid is created using the html unordered list elements.Then inside we put our img tags.Then we have given some styles to the images like height width,floating,positioning etc etc etc.You can see the full code for the grid from the code listed below in this post.

there might be several thumbnail galleries available on the internet,but every one has own way of doing work.the logic may be different.but i have tried to keep the code small as possible.

 

when we gonna click on thumbnail then the that image will show up in the box next to the grid.it exactly look like the image given below.you can see the fading effect in this image given below.

Thumbnail image gallery with jquery

The code is very easy.every one can easily understand the code.i have posted all the code below you can just copy pste the code or download the source from the link given at the end of the post.

see the full code listing:

THE HTML:

<div id="bigbox">

<ul id="box">
	<li><img src="images/12.jpg" title="abstract"/></li>
	<li><img src="images/13.jpg" title="abstract"/></li>
	<li><img src="images/14.jpg"  title="abstract"/></li>
	<li><img src="images/15.jpg" title="abstract"/></li>
	<li><img src="images/16.jpg" title="abstract"/></li>
	<li><img src="images/17.jpg" title="abstract"/></li>
	<li><img src="images/18.jpg" title="abstract"/></li>
	<li><img src="images/19.jpg" title="abstract"/></li>
	<li><img src="images/20.jpg" title="abstract"/></li>
</ul>
<div id="box2">
<img src="images/12.jpg" title="cars" />
</div>
</div>


THE CSS:


#box
 {
 width:400px;
 height:600px;
 float:left;
 }
 #box li {
	margin: 5; padding: 2px;
	float: left;
	left:20px;
	top:50px;
	position: relative; 
	width: 110px;
	height: 110px;
	display:inline;
}
#box li img
 {
 width: 100px;
 height: 100px;
cursor:pointer;
position: absolute;
left: 0; top: 0;
display:inline;
 }
 #box2
 {
 position:relative;
 float:left;
left:30px;
top:50px;
 width:500px;
text-align:center;
 padding:2px;
 }
 
 #box2 img
 {
 width:600px;
 cursor:pointer;
 border:2px solid white;
 }
  #box img:hover
 {
border:2px solid white;
margin-top:5px;
margin-left:5px;
margin-right:5px;
margin-bottom:5px;
 }
 #bigbox
 {
 overflow:hidden;
 }


 

Jquery/Javascript code:

In jquery code for Thumbnail picture gallery,when we click on thumbnail photo then we return the src attribute of that photo and that src attribute is send to that adjacent right side box to the picture grid.means the src attribute is changed on the big image in this thumbnail image gallery.Also when we click on big image then also the image changes,that happens cause we have collected src of all the images inside ul element with id 'box' to an array.

when ever the big picture is clicked that random iamge is choosen from the array.i hope every one knows the concept of array in jquery.actually thats just same as in c++. 

$(document).ready(
 function()
	{
	 $("#box img").click(
			function()
				{
				
					var sr=$(this).attr("src");						
					//alert(sr);
					$("#box2 img").fadeOut("slow",function(){
					$("#box2").html("<img src='"+sr+"' style='opacity:0.30'/>");
					$("#box2 img").fadeTo("slow",1);
					});	
					
					
				}
		);
		$("#box img").hover(
			function()
			{
				$(this).css({'z-index' : '10','border':'4px solid white'});
				$(this).animate({
				marginTop: '-110px', 
			marginLeft: '-110px',
			top: '50%',
			left: '50%',
			width: '200px', 
			height: '200px'			
			},200);
			},function()
				{
					$(this).css({'z-index' : '0','border':'none'}); 
			
				$(this).animate({
					marginTop: '0', 
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '100px', 
			height: '100px'
			
		}, 400);
				}
		);
				
		
	//click on the image
		var length=$("#box img").length;
		var myimage=new Array();
		$("#box img").each(function(n){
				myimage[n+1]=$("#box img:eq("+n+")").attr("src");//alert(myimage[n]);
			});
		$("#box2 img").live('click',function()
				{
				var r=Math.ceil(length*Math.random());
					$("#box2 img").fadeOut("slow",function(){
					$("#box2").html("<img src='"+myimage[r]+"' style='opacity:0'/>");
					$("#box2 img").fadeTo("slow",1);
					});	
				}
			);	
	} 
 );

 

That was the all code.you would also be eager to see the demo and download link for this one.that is below.

 

LIVE DEMO OR DOWNLOAD Thumbnail Image Gallery:

 

LIVE DEMO DOWNLOAD

 

Please hit like and do comment if you like or if you have any problem dont hesitate to ask.i hope you will like this one.may be all begginers find it interesting...

 



Postedby:admin

Posted Under:tutorial    Category:jquery-tutorial

SHARE POST:


SHARE







FACEBOOK COMMENTS




COMMENTS

Write Your Thoughts


Name:

Email:

Comment:




LOGIN


Email:
Password:

Not Registered yet? Sign Up here..


FIND US on FACEBOOK

Blog Archive

Latest News

World News Headlines - Yahoo! News

Get the latest world news headlines from Yahoo! News. Find breaking world news, including analysis and opinion on top world stories.
05/20/2012 01:55 AM
Blind Chinese activist Chen arrives in New York

Blind Chinese dissident Chen Guangcheng is helped from a vehicle as he arrives in New YorkNEW YORK (Reuters) - Blind Chinese dissident Chen Guangcheng arrived in the United States on Saturday and declared "equality and justice have no boundaries" after China let him leave a Beijing hospital to quell a sensitive diplomatic rift between the two countries. Chen escaped from house arrest in northeastern China last month and sought refuge in the U.S. Embassy in Beijing, embarrassing China and creating an uncomfortable backdrop for U.S. Secretary of State Hillary Clinton's visit to improve ties between the world's two biggest economies. ...



05/20/2012 12:28 AM
World leaders back Greece, vow to combat financial turmoil

G8 leaders speak at the start of the first working session of the G8 Summit at Camp DavidCAMP DAVID, Maryland (Reuters) - World leaders backed keeping Greece in the euro zone on Saturday and vowed to take all steps necessary to combat financial turmoil while revitalizing a global economy increasingly threatened by Europe's debt crisis. A summit of the G8 leading industrialized nations came down solidly in favor of a push to balance European austerity - an approach long driven by German Chancellor Angela Merkel - with a new dose of U.S.-style stimulus seen as vital to healing ailing euro-zone economies. But it was clear that divisions remained. ...



05/19/2012 06:58 PM
Syria bomb kills 9, Damascus blames foreign plot

Residents and security personnel gather at the site of an explosion in Deir Al-ZourBEIRUT (Reuters) - A car bomb killed nine people at a Syrian military post in the eastern city of Deir al-Zor on Saturday, an attack the government said was the latest proof that an uprising against President Bashar al-Assad was a foreign plot. The official SANA news agency said the blast had been the work of a suicide bomber, and had also wounded about 100 people, including guards, at what it called military installations. International pressure and an U.N.-backed peace plan has failed to quell Syria's turmoil. ...



05/20/2012 02:26 AM
5.9-magnitude earthquake strikes near Bologna, Italy
(Reuters) - A 5.9-magnitude earthquake struck near Bologna, Italy, on Sunday, according to the U.S. Geological Survey. The quake, which initially registered at magnitude 6.3, was centered 22 miles north-northwest of Bologna in northern Italy at a relatively shallow depth of 6.3 miles, the USGS said. The last major earthquake to hit Italy was a 6.3 magnitude quake in the central Italian city of L'Aquila in 2009, killing nearly 300 people. In January, a 5.3-magnitude quake in northern Italy was felt in Genoa, Bologna, Turin and Italy's financial capital, Milan. (Writing by Doina Chiacu)
05/19/2012 11:52 PM
G8, raising pressure on Iran, puts oil stocks on standby

French President Hollande, U.S. President Obama, Britain's Prime Minister Cameron, Russia's Prime Minister Medvedev and Germany's Chancellor Merkel at the start of the first working session of the G8 Summit at Camp DavidCAMP DAVID, Maryland (Reuters) - Leaders of the Group of Eight major economies raised the pressure on Iran on Saturday, signaling their readiness to tap into emergency oil stockpiles quickly this summer if tougher new sanctions on Tehran threaten to strain supplies. "We remain united in our grave concern over Iran's nuclear program," the G8 leaders said in a statement summing up the results of their meeting in Camp David in rural Maryland. ...



Latest News