Animated tabbed content with jQuery

141

A lot of websites on the Internet have tabbed content now a days. The problem I find with most of them is that most of the time they can be quite dull. For my new looks I created a container which has the ability to switch content through tabs, but with an animation. This tutorial will show you how to create your own tabbed content step by step.

tabbedpost

Download
Tabbed Content zip-archive
Example
View the Tabbed Content in action!

In this tutorial I am going to show you some web development techniques that can be used in your next projects. This will cover some CSS, HTML and jQuery tricks.

The sources of this tutorial are downloadable here: http://www.gayadesign.com/scripts/tabbed/tabbedContent.zip

Example of the outcome is found here: http://www.gayadesign.com/scripts/tabbed/

First thing we need is some basic HTML layout to fit what we are going to make.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>Tabbed content</title>
		<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />

		<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'></script>

		<link href='css/tabbedContent.css' rel='stylesheet' type='text/css' />
		<script src="js/tabbedContent.js" type="text/javascript"></script>
	</head>

	<body>

	</body>
</html>

I already included jQuery and other files in the head section. We’ll be making these files step by step in the next few minutes.

Next thing we need to do is create the structure of the document. What we need is a container with the tabs and a container which the content will that switch if we change tabs.
As a nice feature to enhance this all we’ll use a tab background that will move to the choice the user makes. While this tab moves, the content will also change to the selected tab.

For this we need a container containing the tabs and the background, a container containing the content and container that prevents the content to be shown prematurely.

Take a look at the following code:

<div class='tabbed_content'>
	<div class='tabs'>
		<div class='moving_bg'>
			&nbsp;
		</div>
		<span class='tab_item'>
			Tab one
		</span>
		<span class='tab_item'>
			Tab two
		</span>
		<span class='tab_item'>
			Tab three
		</span>
		<span class='tab_item'>
			Tab four
		</span>
	</div>

	<div class='slide_content'>
		<div class='tabslider'>

			<!-- content goes here -->

		</div>
	</div>
</div>

It’s time to do a little styling to the tabs section and the overall container. Note that in the next part I am going to use an image which is included in the source archive. This will enhance the looks of the tabbed container.

This following CSS will make the tabs appear as tabs:

.tabbed_content {
	background-color: #000000;
	width: 620px;
}

.tabs {
	height: 62px;
	position: relative;
}

.tabs .moving_bg {
	background-color:#7F822A;
	background-image:url(../images/arrow_down_green.gif);
	background-position: bottom left;
	background-repeat: no-repeat;
	left: 0;
	padding: 15px;
	padding-bottom: 29px;
	position: absolute;
	width: 125px;
	z-index: 190;
}

.tabs .tab_item {
	display: block;
	float: left;
	padding: 15px;
	width: 125px;
	color: #ffffff;
	text-align: center;
	z-index: 200;
	position: relative;
	cursor: pointer;
}

Note that the tab container has a position of relative to make the moving background position to it. Now we can easily move the moving background using the left property.

In the next part we are going to add the first few lines of Javascript to the tabbedContent.js file to create a mouseover effect on the tab items.

Use this code as a skeleton:

var TabbedContent = {
	init: function() {	

	},

	slideContent: function(obj) {

	}
}

$(document).ready(function() {
	TabbedContent.init();
});

This code is will execute the init function once the page is loaded.

Now we need to make is so that the moving background moves to the tab item which is hovered on. Implement the following code:

$(".tab_item").mouseover(function() {

	var background = $(this).parent().find(".moving_bg");

	$(background).stop().animate({
		left: $(this).position()['left']
	}, {
		duration: 300
	});

	TabbedContent.slideContent($(this));

});

This will make all the items with the class tab_item behave as if it was a tab. It also moves the moving background to the right position, matching the left property with that of the tab.

TabbedContent.slideContent($(this)); will make the content switch in a few steps. We’ll get to that.

Next up is creating the content and it’s CSS. The content goes in the place we put .

<ul>
	<li>
		This matches the first tab
	</li>
</ul>
<ul>
	<li>
		This matches the second tab
	</li>
</ul>
<ul>
	<li>
		This matches the third tab
	</li>
</ul>
<ul>
	<li>
		This matches the fourth tab
	</li>
</ul>

And the matching CSS:

.tabbed_content .slide_content {
	overflow: hidden;
	background-color: #000000;
	padding: 20px 0 20px 20px;
	position: relative;
	width: 600px;
}

.tabslider {
	width: 5000px;
}

.tabslider ul {
	float: left;
	width: 560px;
	margin: 0px;
	padding: 0px;
	margin-right: 40px;
}

.tabslider ul a {
	color: #ffffff;
	text-decoration: none;
}

.tabslider ul a:hover {
	color: #aaaaaa;
}

.tabslider ul li {
	padding-bottom: 7px;
}

Note that the content has two containers. One is for the overall wrapping and the other for making the content move as we hover over the items.

The top container has an overflow of hidden, which makes any content that goes out of it’s limits hidden. The container below that will hold the content that will be hidden.

Now we are going to make the content scroll to the right position as we did with the tabs.

It’s time to fill up the slideContent function:

var margin = $(obj).parent().parent().find(".slide_content").width();
margin = margin * ($(obj).prevAll().size() - 1);
margin = margin * -1;

$(obj).parent().parent().find(".tabslider").stop().animate({
	marginLeft: margin + "px"
}, {
	duration: 300
});

The margin needed for the slider to move is calculated in this function. It has been made so that you can change the widths of several containers in the result, it will scroll to the right position automatically.

Take another looks at the source for references.

Good luck with making your own tabbed content in your future projects.

Articles like this one

If you liked this article you can add this post to:


 

97 Comments

  1. evan said: April 26, 2009 at 8:30 pm | Permalink

    Awesome man! I would make the area which determines the slider to move to be the <a> rather than the <div>. If content is too far over to the left then mouse could hit the next sections causing the content to change unwarranted.

    Evan


  2. Gaya said: April 26, 2009 at 8:49 pm | Permalink

    Thanks for the comment Evan!
    You have a point there. It would increase the usability of the whole concept. Thanks for sharing your thoughts.


  3. Mike said: April 26, 2009 at 9:38 pm | Permalink

    Very cool! Though, what happens if the user has JavaScript turned off?


  4. Gaya said: April 26, 2009 at 9:44 pm | Permalink

    @Mike: I have no idea… I guess they wont switch :P


  5. Tyler Jefford said: April 26, 2009 at 11:20 pm | Permalink

    Hey! Very cool effect you have made. I really like content sliders.

    Also going along with @mike If the JavaScript has been disabled then none of the tabs work.

    Have a great day!

    -tjefford


  6. Gaya said: April 27, 2009 at 12:12 am | Permalink

    Thanks for the comment Tyler. Maybe the tabs should be clickable if Javascript is disabled.


  7. neki chan said: April 27, 2009 at 11:03 am | Permalink

    coolllll…
    wanna try it
    thanks :D


  8. Farrhad A said: April 27, 2009 at 8:12 pm | Permalink

    Another uber kewl tutorial on GD :)


  9. Peter Witham said: April 27, 2009 at 9:14 pm | Permalink

    Great example and well executed, thanks for sharing.


  10. Gaya said: April 28, 2009 at 8:57 am | Permalink

    @Neki, Farrhad and Peter:

    Thanks for the comments and good luck with trying it out :D


  11. Drew Douglass said: April 28, 2009 at 9:11 am | Permalink

    The effect is super slick and pretty original, different from most tabs I have seen. Keep up this kind of material Gaya, I really enjoy it!

    As for the flaw with JavaScript being disabled, you could try setting the overflow to hidden with JS and set the default CSS to scroll so the user could scroll through the content. Haven’t tested this, just a quick ide from a glance at the demo and code.

    Great work!


  12. Gaya said: April 28, 2009 at 9:16 am | Permalink

    Hi Drew!

    Thanks for checking out the article and commenting! Much appreciated :D

    As for the fix to the problem; it is a solution worth trying. Maybe even make the tabs scrollable with them. I sometimes wonder how many people don’t use Javascript these days.


  13. Hiro said: May 4, 2009 at 5:28 pm | Permalink

    Sweet tutorial :) Appreciate all the details.


  14. Gaya said: May 4, 2009 at 6:24 pm | Permalink

    No problem Hiro! Stick around for more ;)


  15. Ahmet said: May 7, 2009 at 11:37 am | Permalink

    Thanks for this work. This is great! Good work!


  16. Gaya said: May 8, 2009 at 11:01 am | Permalink

    Thank Ahmet! Have fun with it!


  17. Liviu said: May 12, 2009 at 10:06 pm | Permalink

    Thanks for sharing this script, the idea is great. How about converting it into a jQuery plugin?


  18. Gaya said: May 13, 2009 at 8:35 am | Permalink

    I might make a plugin in the near future :) stay tuned!


  19. Raphael said: May 31, 2009 at 5:41 pm | Permalink

    How do i make it animate when the click of the mouse is done instead of the mouseover function?


  20. Raphael said: May 31, 2009 at 6:13 pm | Permalink

    I´ve just solved this problem I have aked for help just by changing mouseover in the js code to mousedown and it worked perfectly


  21. Gaya said: May 31, 2009 at 8:22 pm | Permalink

    @raphael:
    Good! jQuery is really that easy. Glad you liked it :)


  22. dtr said: June 4, 2009 at 9:17 am | Permalink

    Great stuff mate, nice to see someone this creative. Everything work like a charm, but in firefox there’s a problem when you insert the . Keep the great job.


  23. dtr said: June 4, 2009 at 9:23 am | Permalink

    sorry the image tag


  24. Gaya said: June 5, 2009 at 5:09 pm | Permalink

    Hi dtr,

    Are you inserting the image tag inside a ul? that way it should work.
    Good luck :)


  25. dlv said: June 16, 2009 at 4:00 pm | Permalink

    thanks Gaya, it’s a great menu, it’s what i was looking for… i’m using it in my website and looks great

    thanks for share it!!

    PD: a have little question, when you use the menu and click on a tab link, when page reload, the slide button “.moving_bg” is allways in the first position not showing the new open page.
    There is a way to remember the active page, so “.moving_bg” position match with the open page/category?

    thanks in advance!

    adeux, from argentina


  26. W.Dohmen said: June 19, 2009 at 5:44 pm | Permalink

    Looks really nice, just the kind of thing I was looking for thnx for the tut (y)


  27. Vector Man said: July 31, 2009 at 6:02 am | Permalink

    Hi. I think its not comfortable when content links located far away from his title.


  28. Ravikumar V. said: September 16, 2009 at 8:23 am | Permalink

    really nice creative website design.. :)


  29. Siddharth said: September 24, 2009 at 7:34 am | Permalink

    Thanks for your gr8 work. it’s really gr8;

    i have one question: can we use iframe under any tab? i tried but its not showing correctly, please check and update us with ur gr8 work :-) thanks!

    SiD


  30. Gaya said: September 24, 2009 at 4:49 pm | Permalink

    Have you tried putting the iframe inside a list?
    The script was made to move around ul tags. So try to do:
    ul > li > iframe
    good luck!


  31. moabi said: October 19, 2009 at 9:21 am | Permalink

    a very nice slider, simple, efficient, and no click !!!
    check your slider here
    much thanks from him

    http://www.yifan-cirque.com/bio(graphie).php


  32. khits said: October 29, 2009 at 3:41 am | Permalink

    Hi, i’m trying this slider in my website but it’s not working… I followed every step of the instructions but it seems i’m missing something…

    check: http://www.wordofhope.ph/tabbed


  33. khits said: October 29, 2009 at 3:43 am | Permalink

    Hi, i’m trying to put this slider in my website but it’s not working… I followed every step of the instructions but it seems i’m missing something…Will you please tell me what did I missed.

    check: http://www.wordofhope.ph/tabbed.html


  34. Gaya said: October 29, 2009 at 9:12 am | Permalink

    @moabi: Looks cool dude! Glad you liked it :)

    @khits: I see you are missing the jQuery file + the AnimatedTabs file gives a 404. Fix these first.


  35. oh!curiouser said: October 30, 2009 at 12:22 am | Permalink

    Thanks! I like it very, very much!!!


  36. ukwebguy said: November 26, 2009 at 2:39 pm | Permalink

    This is good stuff! Thank you for sharing. I have just one small problem – it works great with 4 tabs but when I try and extend it to 5 or 6 tabs the content stays withing the original 4 tab width no matter what I do to the content width. Would it be possible to have a few instructions on extending this to more than 4 tabs for those of us who are “CSS challenged”?


  37. Chuck Snyder said: December 1, 2009 at 12:46 am | Permalink

    Wonderful little tool. Wow’d the boss.

    I was having a problem displaying 12 tabs. After adding the 5th tab (I was testing as i added each one), they started to double up.

    It took a few minutes to realize what was happening, the .tabslider in the css file was set to 5000px. Adding up the width of the tabs comes up to quite a bit more than 5000px, so upped it to 10000px and now it works just fine.

    Thanks for the good work.


  38. Chuck Snyder said: December 1, 2009 at 6:38 pm | Permalink

    One problem I’m having, I have a couple of GridViews in seperate tabs, and one of the grids is larger than the other.

    How would I make one tab display wider than the others??


  39. Dre said: December 17, 2009 at 11:50 pm | Permalink

    I am interested in using this with the tabs lined up to the left of the content slider above each other. More like buttons than tabs.

    Any ideas?


  40. Nasiba Ansari said: February 17, 2010 at 4:39 pm | Permalink

    Really nice script. I am using in my site.


  41. Kevin said: March 18, 2010 at 2:50 am | Permalink

    hi Gaya, no matter how much I try to put your animated tab into my blog, i can’t do it. Could you please look at my theme for me, and tell me what I did wrong. I am willing to donate to you if you can make your animated script work into my theme.


  42. sajan kota said: March 25, 2010 at 2:46 pm | Permalink

    Looks kool , execellent use of jquery.


  43. diptekosede said: April 2, 2010 at 5:26 pm | Permalink

    Great example and well executed, thanks for sharing.


  44. Michael said: April 19, 2010 at 11:08 am | Permalink

    Hi, How can you make the content to slide verticaly instead of horizontaly? Thanks


  45. ashish said: April 27, 2010 at 2:43 pm | Permalink

    gr8 work….the sliding effect is running but the content is not working when i change the tab. :(


  46. Cingene said: May 10, 2010 at 3:55 am | Permalink

    I found a Bug.
    When i include the newest jQuery 1.4.2 from Google Apis, then in Opera 10.53 your Script are Problems.
    @gaya: Please test it self with jQuery 1.4.2


  47. Criss said: May 18, 2010 at 9:27 pm | Permalink

    comment 37: setting 10000px doesn’t work for me
    comment 45: I got the same problem, content doesn’t appear at all

    Any ideas how to solve the above?


  48. piterPL said: May 19, 2010 at 2:37 pm | Permalink

    It doesn’t work in IE8 ;/


  49. Criss said: May 27, 2010 at 7:10 pm | Permalink

    I would like to have a link inside a tab to go to another tab, keeping the sliding effect. What code should I add ?


  50. Website Design said: June 12, 2010 at 6:53 am | Permalink

    Really very excellent just imagine many many thanks for posting this.


  51. Scrapsforever said: September 10, 2010 at 12:11 pm | Permalink

    Amazing jquery tutorials, its excellent
    thanks


  52. Felix said: October 12, 2010 at 6:46 pm | Permalink

    Muy bueno.. gracias me sera util


  53. Michael Mallett said: October 12, 2010 at 8:59 pm | Permalink

    Is there a way of seperating the tabs from the content switcher in the jquery?

    Having them one above the other really restricts the design, even if it does make for very lightweight coding.


  54. Sol said: November 6, 2010 at 5:24 am | Permalink

    Hi

    I am using a modified version of this excellent script:

    I have it set up to display an individual background image in the main UL content area, along with text sitting on top of the images (for seo).

    Upon hover over the title tab, the new content slides into view – but in IE7 / 8 it only shows the first content tab.

    This works perfectly in all browsers except IE and I am convinced it is the javascript that is not being correctly read by IE. As you can see, I’ve added the .tabslider arguments – which are correctly read by all browsers except IE.

    Being a total javascript newbie – I’m hoping someone here could help me out.

    Here’s the script

    //tab effects

    var TabbedContent = {
    init: function() {
    $(".tab_item").mouseover(function() {

    var background = $(this).parent().find(".moving_bg");

    $(background).stop().animate({
    left: $(this).position()['left']
    }, {
    duration: 300
    });

    TabbedContent.slideContent($(this));

    });
    },

    slideContent: function(obj) {

    var margin = $(obj).parent().parent().find(".slide_content").width();
    margin = margin * ($(obj).prevAll().size() - 1);
    margin = margin * -1;

    $(obj).parent().parent().find(".tabslider1, .tabslider2, .tabslider3, .tabslider4, .tabslider5, .tabslider6").stop().animate({
    marginLeft: margin + "px"
    }, {
    duration: 300
    });
    }
    }

    $(document).ready(function() {
    TabbedContent.init();
    });

    Here’s the CSS

    .tabbed_content {
    background-image:url(../images/slide-back1.png);
    width: 975px;
    height: 400px;
    }

    .tabs {
    height: 62px;
    position: relative;
    }

    .tabs .moving_bg {
    padding: 15px;
    background-color:#ff9900;
    background-image:url(../images/arrow_down_green.gif);
    position: absolute;
    width: 125px;
    z-index: 190;
    left: 0;
    padding-bottom: 29px;
    background-position: bottom left;
    background-repeat: no-repeat;
    }

    .tabs .tab_item {
    display: block;
    float: left;
    padding: 15px;
    width: 125px;
    color: #666;
    text-align: center;
    z-index: 200;
    position: relative;
    cursor: pointer;
    }

    .tabbed_content .slide_content {
    overflow: hidden;
    background-color: #eee;
    padding: 20px 0 20px 0px;
    margin-left:20px;
    position: relative;
    width: 900px;
    }

    .tabslider1, .tabslider2, .tabslider3, .tabslider4, .tabslider5, .tabslider6 {
    width: 7000px;

    }

    .tabslider1 ul, .tabslider2 ul, .tabslider3 ul, .tabslider4 ul, .tabslider5 ul, .tabslider6 ul {
    float: left;
    width: 900px;
    height:200px;
    margin: 0px;
    padding: 100px 0 0 0;
    list-style:none;
    }

    .tabslider1 ul {
    background-image:url(../images/1.jpg);

    }

    .tabslider2 ul {
    background-image:url(../images/2.jpg);

    }

    .tabslider3 ul {
    background-image:url(../images/3.jpg);

    }

    .tabslider4 ul {
    background-image:url(../images/4.jpg);

    }

    .tabslider5 ul {
    background-image:url(../images/5.jpg);

    }

    .tabslider6 ul {
    background-image:url(../images/6.jpg);

    }

    .tabslider1 ul a, .tabslider2 ul a, .tabslider3 ul a, .tabslider4 ul a, .tabslider5 ul a, .tabslider6 ul a {
    color: #666;
    text-decoration: none;
    }

    .tabslider1 ul a:hover, .tabslider2 ul a:hover, .tabslider3 ul a:hover, .tabslider4 ul a:hover, .tabslider5 ul a:hover, .tabslider6 ul a:hover {
    color: #aaaaaa;
    }

    .tabslider1 ul li, .tabslider2 ul li, .tabslider3 ul li, .tabslider4 ul li, .tabslider5 ul li, .tabslider6 ul li {
    padding-bottom: 7px;
    padding-left:40px;

    }

    And here’s the page html:

     

    Cars

    Bikes

    Trucks

    People

    Animals

    Flags


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


    text text text


  55. The 16i Team said: November 8, 2010 at 1:28 pm | Permalink

    Hi,
    This is a very neat bit of code. We are currently using it as a type of “Supermarket Shelf” system on our brand new website.

    http://www.16i.co.uk/

    Are there any plans to update it so that if you are not mousing over the “nav” that the content scrolls automatically?

    Dave@16i


  56. Sol said: November 12, 2010 at 2:39 am | Permalink

    Hi 16i thanks for sharing that – your design helped me understand more about the relationship between this code and images.

    … nice site too….


  57. Alex Coady said: November 19, 2010 at 5:54 pm | Permalink

    I’m very impressed with this tutorial, it’s exactly what I was looking for. However, and this might be really simple, I’m struggling to set different colors for the tab text that isn’t currently selected. (i.e. The name of the tabs that aren’t currently selected).

    Can you think of a simple way to do this?

    Great work!

    alex


  58. Andreas Ash said: November 19, 2010 at 6:43 pm | Permalink

    Please help!

    Have a look at http://www.dj-ash.co.uk with CHROME browser…

    The text if offset and I don’t know how to fix it!

    Works fine with FF and IE…

    please email me at info@dj-ash.co.uk if you can be kind enough

    thanks

    Andy


  59. Julien said: December 5, 2010 at 5:10 am | Permalink

    Thank you for this great script.
    Could you help me set it up in the following way:
    I would like to display some text by default that comes back whenever the mouse is not hovering above a tab.
    Any ideas?
    Thank you!!!


  60. Andreas Ash said: December 21, 2010 at 5:47 pm | Permalink

    The tabbed content script doesn’t work for me in Chrome. The contents are displaced.

    Please have a look at http://www.dj-ash.co.uk

    What am I doing wrong ?


  61. Maria said: January 19, 2011 at 6:34 pm | Permalink

    Great tutorial, This tabs are very very nice for one of my projects, thank you for your help, and congrantulations very nice work.


  62. Oli said: January 26, 2011 at 1:28 am | Permalink

    Is it possible to call the change tab section of the code from general javascript in the page – eg based on the an # url var
    any help would be appreciated.
    Oli


  63. รับทำเว็บไซต์ said: January 30, 2011 at 12:20 pm | Permalink

    Awesome …..! I bookmared it on Delicious and submitted

    on Digg. Hopefully it sends more people your way


  64. dorian said: February 4, 2011 at 11:10 am | Permalink

    Wonderful! thank you! this script is perfect! i was looking for a long time, and this one is what i needed! :-D

    Thanx


  65. Todd said: February 26, 2011 at 6:37 pm | Permalink

    First of all, thanks a lot for this! It’s amazingly nice, and I’m about to use it on a website I’m creating (it’s a simple website, the only animation is this tabbed view :D ).

    Now I read some people wanna know how to change the text color of the tab that’s been hovered on, and I noticed it doesn’t look good if it’s not animated.

    As I do not have a domain yet, I cannot show it, I would upload the source code but I’m afraid someone will steal the design or something.

    Feel free to mail me at todd.david9@gmail.com though!


  66. Abbas said: March 1, 2011 at 5:03 pm | Permalink

    Hiya,
    Great code, I am trying to select middle or right tab by default, can any one kindly help?
    Many thanks in advance.


  67. jaws said: March 7, 2011 at 1:57 pm | Permalink

    “change tab section of the code from general javascript in the page – eg based on the an # url var” << this is the most important feature to add or to explain.

    Any idea ?


  68. Rida57 said: March 13, 2011 at 9:53 pm | Permalink

    My version of it, please let me know what you think
    the render on Mozilla 3.6 is the best one


  69. ludo said: March 22, 2011 at 4:09 pm | Permalink

    Hey,
    great code… i’m trying to use it in my futur website, but i have a little problem…
    i’ve put images in tabbed content, and i want to use lightbox on them, but when i put the lightbox.js, tabbedcontent.js stop to work… how can i do? is it normal?

    thanks!

    ( i’m french so sorry for my language… :)


  70. Eyes Drinker said: April 6, 2011 at 5:35 pm | Permalink

    Very nice, Thank you for effort. Can i change event from mouseover to click?? as some time unintentionally mouse rolled over tab and is selected.


  71. prahalad said: April 19, 2011 at 8:42 am | Permalink

    height is defined, it takes default height for all the tabs content..
    IF first tab has more content, it is taking the same height for other tabs as well even if there is less content…how to assign height according to its content in indivudual tabs,…


  72. Nick said: April 25, 2011 at 9:39 pm | Permalink

    It is a nice tabbing system, with one huge ironic flaw; “Don’t press the TAB KEY from the last item (highest tabindex) on the current tab!”

    What happens is the browser (tested in FF, Chrome, IE and Safari) shifts the content, but only by the amount of space required to show the next item in the tabindex, which in my case is the first input box on the next tab. At that point, changing the tabslider left margin or the moving_bg left margin to correct values has no effect on restoring the screen. The browser, in effect, gets stuck between tabs until you issue a reload of the page.

    At first I thought I could compensate for this defect, since I created a routine to position the tabs to any initial tab on a page reload via a $_POST value. But no go. Once the browser gets stuck in between it’ll stay that way.

    Go ahead. Check it out with the demo. Repeatedly strike the tab key until it tries to bring the focus to a tabindex on another tab.

    I’ve tried a number of techniques involving onKeyPress, etc. but I believe this is beyond my expertise.

    In my case, I’m using the tabslider as an input wizard, so the ability to tab from one tab to the next is critical.

    It would be nice to have a fix for this problem. It’s otherwise a very handy routine.

    Thank for the slider!


  73. marcus said: May 6, 2011 at 2:47 pm | Permalink

    Hi, great tutorial! Is it possible to have the menu revert to its original position on mouseout?

    Thanks!


  74. Kary Ockerman said: May 19, 2011 at 11:07 am | Permalink

    Hey there! This is my 1st comment here so I just wanted to give a quick shout out and say I really enjoy reading your posts. Can you suggest any other blogs/websites/forums that go over the same topics? Many thanks!


  75. miguel said: May 31, 2011 at 2:46 am | Permalink

    hi !! it’s great… but….. only work with jquery 1.3 ? :( not work with jquery 1.6 ? or 1.4 ? :(


  76. Trek said: June 20, 2011 at 6:20 pm | Permalink

    I was pleased to find you script but I am a novice and do not know how to associate each tab to individual content. Is the code you provide generic and needs to be customized?

    I spent time on the look and feel by changing CSS settings, but what do I put in the DIV tag to connect with each tab?

    Confused… ??


  77. Trek said: June 20, 2011 at 7:14 pm | Permalink

    OOPS… never mind… haa… it was right in front of me!!


  78. Samson said: July 3, 2011 at 5:35 pm | Permalink

    Fantastic, i really love this. but, what if i dont want d tab function to change on “hover state”, i want it to change when u “click” on the tab!!! what am i to alter in d jQuary?


  79. Pbnj4640 said: July 25, 2011 at 2:56 pm | Permalink

    this is an awesome slider, thank you! im trying to modify it to run vertically and ive edited all the css and everything, the JS i cannot for the life of me figure out… the content is fine right to left, but i wanna make the tabs themselves run top to bottom and i have no idea what im doing?


  80. hitomi gilliam floral designer said: August 8, 2011 at 10:52 pm | Permalink

    Great blog man, had a lot of great reads! just like to see you update your site now, that would be great!


  81. Mike said: August 10, 2011 at 9:02 am | Permalink

    A very nice and simple tool! Is there a way to animate the moving function after a timeoout?


  82. Marla Silker said: August 18, 2011 at 2:49 pm | Permalink

    When i quite prefer whatever you submit in this article. Extremely useful in addition to smart. Just one challenge though. I’m running Internet explorer having Debian in addition to elements of this present web design portions undoubtedly are a very little wonky. When i understand it’s an excellent normal established. Yet still it’s an issue to help retain in view. When i trust so it can guide in addition to always keep in the prime excellent publishing.


  83. Anders said: August 19, 2011 at 6:46 pm | Permalink

    Great tutorial, and just a genius bit of jQuery ;) I love looking over people’s code to see what they’ve done and it’s very nicely coded! So SIMPLE. Thanks for the script it’s awesome.


  84. Julián said: August 20, 2011 at 6:24 pm | Permalink

    How can i make it work in a WordPress page, i tried and it did worked!


  85. suplementy said: September 8, 2011 at 9:32 pm | Permalink

    Some really wonderful posts on this web site , appreciate it for contribution.


  86. Cheap UGG sale said: September 8, 2011 at 10:25 pm | Permalink

    I concede, I have not been on this site for a long time, however, it was another pleasure to see such an important issues and neglect it. Thanks for assisting making people realize that best issues.


  87. suknie ślubne radom said: September 8, 2011 at 11:21 pm | Permalink

    It’s best to participate in a contest for one of the best blogs on the web. I’ll advocate this website!


  88. Nightclub Dresses said: September 10, 2011 at 3:47 pm | Permalink

    Thank you for your wonderful post! It has long been very valuable. I hope which you will proceed sharing your wisdom with us.


  89. 8mediaeg said: September 12, 2011 at 10:46 am | Permalink

    amazing ,, i like it ,,


  90. Abbott said: September 15, 2011 at 9:25 am | Permalink

    forums which are above the same subject matter? Thank you!


  91. gulflee said: September 17, 2011 at 2:38 pm | Permalink

    thank you for the idea, is there a way to control the height of each eab content? dynamic i mean, it seem the height is following the highest tab-content. any idea.. thank u


  92. Nick said: October 3, 2011 at 11:31 pm | Permalink

    How to initializing selected tab? Please help… ;-(


  93. econ said: October 10, 2011 at 9:31 am | Permalink

    ‘cute’ it’s really help full
    thank you


  94. Ron L. said: October 16, 2011 at 6:40 pm | Permalink

    It doesn’t work well. I made 26 tabs (alphabet) and the tabs content are all over the place. It seems to work well until 8th


  95. Peter Klauer said: October 22, 2011 at 8:09 am | Permalink

    Great!!

    But we put some forms into the sliders and after saving always the starting slider was shown. This was a “jumping” effect. If the user fills some data into a slided form it would be nice if that form would be shown after reload.

    So I wrote a litte function “gotab” which “goes” to a specific tab.

    All you need to do is to put an id in the .tab_item span which needs some positioning:

    Termine

    To position to the tab “tab-kurse” after saving some data, PHP makes a string $js which is injected into the $(document).ready() at page-building time.

    $js = ‘ TabbedContent.gotab($(“#tab-termine”)); ‘;

    And here is the gotab function:
    (Pleas notice the comma at the beginning, which allows pasting into tabbedContent.js)

    ,

    gotab: function( obj ) {

    var background = $(obj).parent().find(“.moving_bg”);

    $(background).stop().animate({
    left: $(obj).position()['left']
    }, {
    duration: 300
    });

    TabbedContent.slideContent( $(obj) );

    }

    As you see it is a simple variation of init().

    @Ron L.: Look in the CSS. Make .tabslider 180000px wide.


  96. praveen kumar said: November 11, 2011 at 12:55 pm | Permalink

    Thanksz ..a lott,

    for your nice “tabbed Content” , really a nice source


  97. Sharon said: January 17, 2012 at 12:17 am | Permalink

    Hi Peter Klauer, I really need the functionality you made and love using these tabs, but I cannot get it to work using your, would you be so kind as to post up your source files so I can see it in action? I have been trying for hours! Thank you.


Leave a Comment

Your email is never shared. Get your own avatar with gravatar! Required fields are marked *

*

*



 

44 Trackbacks

  1. By Visual-Blast Media on May 4, 2009 at 8:19 pm
  2. By CoryMathews.com » 12 Slick jQuery Plugins on August 17, 2009 at 1:40 pm
  3. By 25+ jQuery Tutorials Roundup | ExtraTuts on August 17, 2009 at 8:33 pm
  4. By Dailyinvention.com on October 10, 2009 at 3:31 am
  5. By 50 Cool CSS Menus, Free Source Codes + Tutorials on October 30, 2009 at 7:44 am
  6. By 15 amazing jquery tabs tutorials | ExtraTuts on December 2, 2009 at 7:06 pm
  7. By Nice Jquery Tabs « anil's Blog on January 29, 2010 at 5:14 pm
  8. By 30 CSS and Javascript Tabs Solutions « UKWDS! on September 10, 2010 at 12:39 pm
  9. By 30 CSS and Javascript Tabs Solutions « infomisa.net on September 17, 2010 at 9:55 am
  10. By Tabs using Jquery demo and download links. on September 22, 2010 at 8:46 pm
  11. By The Blog » FAQ: The Bureau on August 5, 2011 at 12:18 am
  12. By Allusion Online FAQ: The Bureau on August 13, 2011 at 3:40 pm
  13. By 10 jQuery Tabs Tutorials | jQuery4u on October 20, 2011 at 10:09 am
  14. By 30 awesome jQuery Tabs | ExceptionHandle.com on November 21, 2011 at 7:29 pm