HiFi CMS

Web Publishing made Less Complicated and More Powerful

A Zoomable jQuery Image Gallery Called jPhotoGrid

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

Joel Sutherland
Joel Sutherland

| Permalink

This post originally appeared on the New Media Campaigns Development blog.
123doing
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.

Leave a Comment

URLs will be converted to links. HTML tags will be converted to entities.