A Zoomable jQuery Image Gallery Called jPhotoGrid
View the Demo | Download the Zip
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.


Comments
Joel Sutherland
123doing
webunique
Sandeshaya
Thanks.
dansk
Hemsida
capri pants for women
طراحی سایت
Leanne
Luca
Ries
john
Sena Kendali
Scott Vitale
Alex
cyberpine
I'm trying to use your solution inside an ASP.NET Content Page of MasterPage with a Repeater control. It renders and works nicely. But I can't seem to to keep the the html unstructured list inside the contentplaceholder .. this might just be an html issue. I've posted my question on stack over overflow here:
http://stackoverflow.com/questions/12237638/kepping-html-lists-ul-li-inside-asp-net-contentplaceholder
cyberpine
sagebrushsoul
I was wondering if it is possible to instead of an overlay, put another picture on top and when you hover the bottom picture shows and when click the bottom picture enlarges. I really like this look!
elang ajib
elang ajib
Rafia
Thank You
Bob
function select(el){
hideSelected(function(){
settings.selectedCSS.left = $(el).position().left - 50;
settings.selectedCSS.top = $(el).position().top - 60;
$(el).addClass('selected').removeClass('active');
$(el).animate(settings.selectedCSS, 'slow');
});
}
What this does is pick up the current screen location of the thumbnail, and then positions the expanded image at the same same top/left location (less 50,60 pixels). That way, users can scroll down a long list and still see the expanded image. Can't remember if I had to mess with the CSS?
Dan
Leave a Comment