Submit your widget

simple Zoomable Images Gallery Called jPhotoGrid with jQuery

Created 7 years ago   Views 45036   downloads 6074    Author gethifi
simple Zoomable Images Gallery Called jPhotoGrid with jQuery
View DemoDownload 4.8 KB
235
Share |

This plugin takes a simple list of images and captions and turns it into a grid of photos that can be explored and zoomed.

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'
 }
 });