Wednesday, April 6, 2011

10:31 AM
Content Tabs have become more popular lately with more and more websites and blogs using them to show more content in lesser space. Today I am going to show you how to create content tabs with nice flipping effect.

For this, you will need the QuickFlip jQuery Plugin by Jon Raasch and of course, the latest version of the incredible jQuery library.

The HTML Structure

Here’s the HTML structure you’ll need to use:

<div id="flip-tabs" >
<ul id="flip-navigation" >
<li class="selected"><a href="#" id="tab-0"  >Recent</a></li>
<li><a href="#" id="tab-1" >Popular</a></li>
<li><a href="#" id="tab-2" >Comments</a></li>
<div id="flip-container" >
<!--Put Content for first tab here-->
<!--Put Content for second tab here-->
<!--Put Content for third tab here-->

You can add as many tabs as you like just add more div tags inside the flip-container div and to make them accessible, do add entries in the flip-navigation list to make navigation tab for new div’s. The id field of a tag in the flip-navigation list items is important.

The id’s are of type tab-x where x is the index of the content div in the flip-container. The index starts from zero, so if you add a new div below the third content div, then the id of the navigation link corresponding to it will be tab-3.

Another thing to keep in mind is the selected CSS class, that is added to the navigation item corresponding to currently open content tab.

The CSS Styles

Here are a few styles i applied to the above HTML structure. These can be customized to whatever you want.

margin:20px auto; position:relative;
margin:0 0 10px; padding:0;
#flip-navigation li{
#flip-navigation li a{
text-decoration:none; padding:10px;
color:#333; outline:none;
font-family:Arial; font-size:12px; text-transform:uppercase;
#flip-navigation li a:hover{
#flip-navigation li.selected a{
font-family:Arial; font-size:13px;
#flip-container div{

The JavaScript Code

Finally, the javascript code that will make your flipping content tabs work:

//initialize quickflip

$('#flip-navigation li a').each(function(){
$('#flip-navigation li').each(function(){
//extract index of tab from id of the navigation item
var flipid=$(this).attr('id').substr(4);
//Flip to that content tab
$('#flip-container').quickFlipper({ }, flipid, 1);

return false;

Code Explanation: 

On document ready, we initialize the quickflip plugin as on Line 3 by calling it for flip-container div. One thing to keep in mind is that if you change the id of flip-container div, remember to change it in JavaScript too.

After that the click event of navigation list is controlled and on click, the clicked item is added theselected CSS class and we call the quickFlipper() function to flip to the selected content tab.
quickFlipper() function allows you to control the speed of flipping by providing options in the first parameter.

quickflipper({ openSpeed:200, closeSpeed:250 }, flipid, 1);

Also, do not change the value third parameter which is the number of times the flip event occurs. You can read more about quickFlipper function here.

Tell me how you liked this tutorial and provide with suggestions for improvement.