Join our HiFi mailing list to receive the latest news & updates

A Zoomable jQuery Image Gallery Called jPhotoGrid

11 Comment(s) | Posted | by Joel Sutherland | |

View the Demo | Download the Zip

jphotogrid screen

The screenshot above is jPhotoGrid in action.  This plugin takes a simple list of images and captions and turns it into a grid of photos that can be explored and zoomed.  You can check out a demo here.

Overview

Nearly all of the styling for this plugin is done in css.  The trick is to layout the grid by floating the list items.  The first thing the plugin will then do, is convert these all to absolutely positioned.  This is what allows the plugin to zoom in on an individual image and then return it to its place.  Like my interactive map plugin, this depends on the browsers ability to scale images.  In my stylesheet, the images are set to width:100% and I simply animate the size of the container.

The Markup

The html for this plugin is simply an unordered list of images and captions.  Here is the format:

<ul>
	<li>
		<img src="/hifi/site/edit/blog/source.jpg" alt="" />
		<p>Caption Here</p>
	</li>
	...
</ul>

The CSS

The CSS is also fairly straight-forward.  The key things to notice are the .active and .selected classes.  When you hover over a list item, it is given the class 'active'.  Once you have clicked the list item, it is given the 'selected' class.

#pg { position: relative; height: 585px; background: #000; }
#pg li { position: relative; list-style: none; width: 175px; height: 117px; overflow: hidden; float: left; z-index: 2; opacity: .3; }
#pg li.active { opacity: 1; }
#pg li.selected { opacity: 1; z-index: 99; -moz-box-shadow: 0px 0px 10px #fff; -webkit-box-shadow: 0px 0px 10px #fff; }
#pg li img { display: block; width: 100%; }
#pg li p { color: white; margin: 10px 0; font-size: 12px; }

The Javascript

The javascript is easy enough to set up.  It needs to know the sizing of the thumbnails as well as the sizing and positioning of the zoomed image.  This is how the plugin is able to zoom and restore each of the images.  Note that you can also change the active and selected classes by setting them using the 'activeClass' and 'selectedClass' options.

$('#pg').jphotogrid({
	baseCSS: {
		width: '175px',
		height: '117px',
		padding: '0px'
	},
	selectedCSS: {
		top: '50px',
		left: '100px',
		width: '500px',
		height: '360px',
		padding: '10px'
	}
	});

Conclusion

While not nearly as extensible or flexible as most of the plugins I like to put together, I enjoyed this one.  It is a fun way to explore a gallery of images and ends up working great in conjunction with the jFlickerFeed Flickr Plugin I put together last week.  If you have any questions or comments, leave them below.

View the Demo | Dowload the Zip

11 Comment(s) | Posted | by Joel Sutherland | |

Comments

  1. Joel Sutherland's avatar
    Joel Sutherland
    | Permalink
    This post originally appeared on the New Media Campaigns Development blog.
  2. 123doing's avatar
    123doing
    | Permalink
    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.
  3. webunique's avatar
    webunique
    | Permalink
    Thank. Very good plugin
  4. Sandeshaya's avatar
    Sandeshaya
    | Permalink
    Nice, clear, works.
    Thanks.
  5. dansk's avatar
    dansk
    | Permalink
    Looks very cool but can't get it to work with JQ Touch for mobile web app. Tried replacing hover with clicks but no joy...
  6. Hemsida's avatar
    Hemsida
    | Permalink
    Great artivle. Thanks for sharing
  7. capri pants for women's avatar
    capri pants for women
    | Permalink
    Thanks for the code. Somehow I'll find out how to use it.
  8. طراحی سایت's avatar
    طراحی سایت
    | Permalink
    thank for sharing
  9. Leanne's avatar
    Leanne
    | Permalink
    Is there a way to remove the white border surrounding the zoomed in image?
  10. Luca's avatar
    Luca
    | Permalink
    Hi all, I can't change the value under each photo. If I do, i get a blank page.
  11. Ries's avatar
    Ries
    | Permalink
    Can somebody tell me if it's possible to have one photo already zoomed when opening the page?

Leave a Comment

Latest on Twitter

Glad it was helpful! RT @vikingux: Learning and testing Regular Expressions? Made much easier with HiFi RegExp Tool: http://t.co/KwOHcuLr

by GetHiFi on web