Submit your widget

jQuery Photo filter lightbox Gallery plugin

Created 11 years ago   Views 45808   downloads 12377    Author flashuser
jQuery Photo filter lightbox Gallery plugin
View DemoDownload
Share |

we'll show you how to create a minimalistic jQuery photo gallery. You can use it to present your latest works or as a photo album. You can sort projects / photos via categories menu. The gallery is cross-browser compatible so it’ll be easy for you to adapt in your project.

For this tutorial I’ve used two free jQuery libraries: Quicksand and PrettyPhoto. You can see the result that I’ve achived by combining this two jQuery plugins by clicking the preview button below. You can use the jQuery gallery in your own projects, just download the package for having access to the files. Let’s see now how the jQuery Photo Gallery was done.


First create an unorded list that will contains the categories. For each category make sure will add a class with a unique name.

<ul class="portfolio-categ filter">
      <li class="all active"><a href="#">All</a></li>
            <li class="cat-item-1"><a href="#" title="Category 1">Category 1</a>
    <li class="cat-item-2"><a href="#" title="Category 2">Category 2</a>
    <li class="cat-item-3"><a href="#" title="Category 3">Category 3</a>
    <li class="cat-item-4"><a href="#" title="Category 4">Category 4</a>

Now create a second list for the items you would like to show. An object will look like this.

<li class="portfolio-item2" data-id="id-0" data-type="cat-item-4">
                   <span class="image-block">
                    <a class="image-zoom" href="images/big/pic1.jpg" rel="prettyPhoto[ gallery ]" title="Wall-E"><img width="225" height="140" src="images/thumbs/p1.jpg" alt="Wall-E" title="Wall-E" />
                   <div class="home-portfolio-text">
                    <h2 class="post-title-portfolio"><a href="#" rel="bookmark" title="Wall-E">Wall-E</a></h2>
                    <p class="post-subtitle-portfolio">released: 2008</p>

There are 3 important things here that you have to take care: data-id – must be unique, data-type – include the item in a category by typing a class name for a specific category, rel=”prettyPhoto[ gallery ]“ – used to open a large photo when the thumb image is clicked.

The CSS code for an item is pretty simple:

.image-block{ display:block;position: relative;}
.image-block img{border: 1px solid #d5d5d5; border-radius: 4px 4px 4px 4px;background:#FFFFFF;padding:10px;}
.image-block img:hover{border: 1px solid #A9CF54;box-shadow:0 0 5px #A9CF54;}
.portfolio-area li{float: left;margin: 0 12px 20px 0;overflow: hidden;width: 245px;padding:5px;}

Now let’s add the jQuery code for the Quicksand filter categories.

// Clone applications to get a second collection
    var $data = $(".portfolio-area").clone();
    //NOTE: Only filter on the main portfolio page, not on the subcategory pages
    $('.portfolio-categ li').click(function(e) {
        $(".filter li").removeClass("active");
        // Use the last category class as the category to filter by. This means that multiple categories are not supported (yet)
        var filterClass=$(this).attr('class').split(' ').slice(-1)[0];
        if (filterClass == 'all') {
            var $filteredData = $data.find('.portfolio-item2');
        } else {
            var $filteredData = $data.find('.portfolio-item2[data-type=' + filterClass + ']');
        $(".portfolio-area").quicksand($filteredData, {
            duration: 600,
            adjustHeight: 'auto'
        }, function () {
        return false;

Here’s the code for the prettyPhoto big image preview.

            overlay_gallery: false

The article source: