Tobias Ahlin is a great designer from Sweden, I admire his work and his way showcasing his portfolio. It comes up with the list of all his works and the anchor for filtering work type above them, we can choose one of the filter and it’s automatically hiding and showing portfolio item using horizontal slide effect. Now, in my view, I am going to explain how they beautifully works.
The Technique
As you can see on the demo page, the image items are showing and hiding with horizontal slide effect based on user choice. Horizontal slide effect produced by manipulating item’s width, when hiding the item we will change the item width into 0 pixel, and when showing the item we will return its default width.
To make the item’s width transformation smooth we will also change its opacity, for hiding the item set the opacity from 100% to 0% and vice versa for showing them. We can show and hide the item but we won’t see the slide effect transition, so we must use built-in jQuery function, animate().

Setup The Item’s View
We’ll create two separated section, first the navigation and the last is the items list. The navigation will contains anchor links which will navigate the items visibility, while items list will contains image item which will be show and hide.
Now, create navigation and items list like following script :
<ul class="menu"> <li class="selected"><a rel="all" href="#">All Tutorial</a></li> <li><a rel="jquery" href="#">jQuery Tutorial</a></li> <li><a rel="css" href="#">CSS Tutorial</a></li> <li><a rel="psd" href="#">Free PSD</a></li> </ul> <ul class="item"> <li><img src="images/button.jpg" alt="" /></li> <li><img src="images/codesnippet.jpg" alt="" /></li> <li><img src="images/css.jpg" alt="" /></li> <li><img src="images/css2.jpg" alt="" /></li> <li><img src="images/psd.jpg" alt="" /></li> <li><img src="images/groovershark.png" alt="" /></li> <li><img src="images/stylize.jpg" alt="" /></li> <li><img src="images/psd2.jpg" alt="" /></li> </ul>
As you mention above, each navigation and item has rel attribute that represent each category. The purpose is when user choosing one of the navigation, the items that will be displayed only an item which has same rel attribute with the navigation, the others will be hidden.
We will styling the navigation first, set the list display with inline-block so the unordered list will be displayed horizontally. If the user select one of the navigation, we will add “selected” class name to them. “selected” style are having green background with box-shadow and border radisu, so the selected navigation will have different style with the siblings.
ul.menu { margin-left: .5em; margin-bottom: 1em; } ul.menu li { list-style-type: none; display: inline-block; font-weight: bold; text-shadow: 1px 1px 0px #f3f5da; padding: 2px 15px; } .selected { -webkit-border-radius: 15px; -moz-border-radius: 5px; border-radius: 5px; background: #acac75; -webkit-box-shadow: 1px 1px 0px #8c8c5d; } .selected a, .selected a:visited { text-shadow: 1px 1px 0px #8c8c60; color: #fff; }

Now styling the image items, set each item display with block, list style type with none, float with left and margin with 0.5 em. Each image inside the list will have 5pixels white border thickness, border radius 5 pixels and also box shadow.
ul.item li { list-style-type: none; display: block; float: left; margin: .5em; } ul.item li img { border: 5px solid #fff; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 0px 0px 5px #ac987e; -moz-box-shadow: 0px 0px 5px #ac987e; box-shadow: 0px 0px 5px #ac987e; }

Slide Effect With animate()
The slide effect will fire up when user click the navigation, so we will add click event to them. After that, remove “selected” class name from all navigation and add it to selected navigation. This will make selected navigation will have different style with its siblings.
$('.menu li a').click(function() { $('.menu li').removeClass('selected'); $(this).parent('li').addClass('selected');
Next, get its rel attribute value and check it. If the value is “all” (which mean showing all image item) we will display all image item and if the value is other we will search any image item that has same rel attribute value and display it then hide the others.
thisItem = $(this).attr('rel'); if(thisItem != "all") { $('.item li[rel='+thisItem+']').stop() .animate({'width' : '110px', 'opacity' : 1, 'marginRight' : '.5em', 'marginLeft' : '.5em' }); $('.item li[rel!='+thisItem+']').stop() .animate({'width' : 0, 'opacity' : 0, 'marginRight' : 0, 'marginLeft' : 0 }); } else { $('.item li').stop() .animate({'opacity' : 1, 'width' : '110px', 'marginRight' : '.5em', 'marginLeft' : '.5em' }); } })
As you can see above, for displaying the item we search all item which having same rel attribute value with the selected navigation. Then we start the animation which will animate the item width to the image’s width, set its opacity to 100% and set each margin left and right to 0.5em. To prevent animation queue, we use stop() function before animate() function.

For hiding the sibling we use the same technique as above except the animation properties’s value, set each animation properties’s value to 0.
At this point our item will be show and hide using slide effect, triggered by the navigation. The last thing we will do is to make the image items smoother by adjusting its opacity. Set each image opacity to 50% using animation and hover toggle event, if the user hovering it, animate its opacity to 100% and revert it value to 50% when user hovering out.
$('.item li img').animate({'opacity' : 0.5}).hover(function() { $(this).animate({'opacity' : 1}); }, function() { $(this).animate({'opacity' : 0.5}); });
Ok, that’s. It thanks for reading and hope this post useful
Filter Image View Using jQuery (via @hdytsgt)
[Community News] jQuery Fundamentals
RGraph : HTML5 Canvas Graph Library
jQuery Plugin : jQuery iPhone UI
Pikachoose : Another jQuery Plugin for Image Gallery
HTML5 Security Cheatsheet
[Community News] How to turn any jQuery plugin into a Wordpress one
Zoom Your Element Using Zoomooz.js
[Community News] Build a Flash-like Game With Scripty2
[Community News] CSS3 Transitions available on Firefox 3.7
[Community News] CSS from the Ground Up
- How To Create iPhone-Style Navigation (Part I)
This post has got 23 shouts so far - jQuery Plugin : jConfirmAction
This post has got 34 shouts so far - iPhone-Style Navigation:AJAX + Rotate (Part II)
This post has got 12 shouts so far - Simple Flip Puzzle Effect with jQuery
This post has got 6 shouts so far - Howto Create Mac-like Login Form
This post has got 7 shouts so far - Implement Password Strength Meter & Gauge.js
This post has got 8 shouts so far - Stylize Your Own Checkboxes
This post has got 15 shouts so far - Create Animated Navigation Menu From Stratch
This post has got 7 shouts so far
- Looks nice
by TheShadow on Filter Image View Using jQuery - Nice drop down menu tutorial.
by TheShadow on Simple CSS3 Dropdown Menu - love your site
by eJobsViet on Free Web UI Element Pack - @Andrew Ellis & @Hidayat Sagita take a look at this little test...
by Pomeh on jQuery Plugin : jConfirmAction - Hi, noob question, how do I use WebUI in WordPress and how do I use these...
by martin on Free Web UI Element Pack




Federica Sibella
Oh very nice! I like the effect and I think I’ll use something like this for the restyling of my own portfolio.
Thanks for sharing!
Marcus Tucker
Great effect! Reminds me a little of Quicksand (http://razorjack.net/quicksand/) but your effect has its own unique charm! I suggest that you turn it into a proper plugin, stick the code on Google Code (or GitHub) and add it to the jQuery Plugin repository at http://plugins.jquery.com/
mike
That’s a really useful filter. I wonder whether it’s possible to add multiple keyword-tags to the items rel attribute? Like this:
rel=”jquery css psd”
Alan
Great wee tutorial, and exactly what i was looking for as part of my portfolio.
Thanks!
Hidayat Sagita
@All thanks for your comments!
Credits for Tobias Ahlin for his great idea!
@Marcus Tucker
That’s a great idea, but I think I need to talk to the author of the idea first
@mike
Certainly you can do that, for finding the items you can use attribute contains word selector : [rel~=value]
Sarah William
Great tutorial…Thanks. I’m trying to get into using more jQuery it does some really cool things..
Rich Mathis
Thanks for sharing! Very nice effect achieved with such minimal coding.
Beben
thanks mate Tobias Ahlin
:”>
matur nuwun kang H.Sagita…
hmmm…any Mrs Sarah William theres…;))
Deluxe Blog Tips
The javascript code looks not very complicated, but it does a great job. The effect is very cool. Thank you very much for this tutorial.
Dolido
Thank you for this tutorial.
deb
thank you for the code! i can not get fancybox.net to work on my images.
my filters are:
ALL ONE TWO THREE
using fancybox:
- filter ALL, select and image ….works-launches fancybox
- filter ONE , select and image ….DOES NOT launch fancybox
- go back and filter again on ALL, select and image ….DOES NOT launch fancybox
any help greatly appreciated
Hidayat Sagita
@deb :
Hi, would you please put your online example so I can also try an debug your code.
kris
Awesome tutorial!!
I had been working on something similar but for some reason it refused to work in IE but glad to see the is cross-browser compatible!
One question though… The animations dont seemt o be working in Safari?? Is it just my Safari or is there a fix I can use for this??
Hidayat Sagita
@kris
Thanks kris! I created them while using Safari and they’re works fine, would you please put the problem detail?
Jason
Great work! Exactly what I have been looking for. I know you touched on this above, but I’m confused on how to implement it in the script.
I have several items that will fall under multiple categories. One item may be included under css and jquery.
“use attribute contains word selector : [rel~=value]“. Where does this go and what changes in the script. I tried swapping [rel!='+thisItem+'] with [rel~='+thisItem+'] but it didn’t work.
Hidayat Sagita
@Jason If you want to select any div element that having ‘rel’ attribute with value ‘blah’ you can do this : $(’div[rel~=blah]‘) or select any div element that having ‘rel’ attribute without value .
In this case you can’t swap them, if you have multiple categories you can put category name on each list in rel attribute.
Angeni
Very cool and useful tutorial! I have one question though. How can we make it work with multiple rel values? It works with rel=”abc” but it doesn’t work with rel=”abc def”.
This question have been aksed here already but still I can’t figure it out.
I’ve got my portfolio items under multiple categories and I’d like it to work with multiple rel=”" attributes. Is this possible?
JRS
Great code! Can you please explain a little more about having multiple categories. Like Jason, I cant seem to get the ‘use attribute contains word selector’ to work properly.
Matteo
This and Tobias’s script have a bug : the last item not disappear after filtering. If you roll over last item, the link is active.
I’m searching for.. if i found the solution, i’ll post here.
Thanks.
Matteo
This solution seems to work :
$(’.item li[rel!='+thisItem+']‘).stop().animate({’width’ : 0, ‘opacity’ : 0,’marginRight’ : 0},function(){$(’.item li[rel!='+thisItem+']‘).css(”display”,”none”);});
I’m wating for a better solution..
regards.
Matteo
$('.item li[rel!='+thisItem+']').stop().animate({'width' : 0, 'opacity' : 0,'marginRight' : 0},function(){
$('.item li[rel!='+thisItem+']').css("display","none");});
You have to hide (display:none) the non-selected item after the transition.
It seems to work.
Bye.
Matteo
I’va found a solution but i can’t post code here.
You have to hide (display:none) the non-selected item after the transition.
It seems to work.
Bye.
Alex Glover
rel~=’+thisItem+’]’ doesn’t seem to be working.
Chris
@Alex – found this and it works. http://forum.jquery.com/topic/multiple-values-in-rel-attribute-doesn-t-work
Dave Whitehead
Hi There, great script by the way.
Unfortunately the HTML5 specification will not allow ‘rel’ on a element.
do you know a way round this at all?
Many thanks
Yael
Hi there,
Excellent code! Just one question…
What would you do if one tutorial had 2 or more topics (let’s say css and psd) and you wanted to show it when clicking on any of the 2?
Thanks!
TheShadow
Looks nice