Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 125
  • Last Modified:

Adding a fadeOut to tabs

I'd like to add a fadeout to the tabs on my page here, if someone could help with the javascript side?

Here's the html:

      
<ul class="tabs clearfix">
		<li class="aboutustab active" style="border-left:1px solid #ccc;"><div class="up"></div>About</li>
		<li class="maptab"><div class="up"></div>Map</li>
        <li class="featurestab"><div class="up"></div>Features</li>
		<li class="voucherstab"><div class="up"></div>Offers</li>
	</ul>

Open in new window


And the here's the javascript:

$(window).load(function(){
	
	$('.tab:not(.aboutus)').hide();
	
	$('.tabs li').click(function(){
		var thisAd = $(this).parent().parent();
		$(thisAd).children('.tab').hide();
		$(thisAd).children('.'+$(this).attr('class').replace('tab','')).show();
		$('.tabs li').removeClass('active');												 	
		$(this).addClass('active');
	});

	
	if(window.location.hash) {
		if (window.location.hash == "#map") {
			$(".Advert").children('.tab').hide();
			$(".Advert").children('.map').show();
			$('.tabs li').removeClass('active');												 	
			$('.maptab').addClass('active');
		}
		if (window.location.hash == "#voucher") {
			$(".Advert").children('.tab').hide();
			$(".Advert").children('.vouchers').show();
		}
	}	
	
});

Open in new window

0
UName10
Asked:
UName10
  • 5
  • 5
1 Solution
 
APoPhySptCommented:
if you want to give the fadeIn and faceOut effect to a hide / show in javascript, you only need pass an integer number, expressed in milisecconds to the hide / show function. Like

$("somediv").show(400);

Open in new window

0
 
APoPhySptCommented:
or if you only want a 'roll effect' try  :

$("p").slideUp(600);

Open in new window

and
$("p").slideDown(600);

Open in new window


example: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_eff_slideup_slidedown
0
 
UName10Author Commented:
Hi, thank you both for answering and I'd like to try the slide effect too.

Could you please show me where I need to add the fade/slide effect to all tabs in the code I posted?

I.e. could you incorporate into my code what I need to add exactly to make all tabs have a fadeout transition? That would really help.

Many thanks
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
APoPhySptCommented:
it depents on where you want get the effect, but I'd say in every .show() and .hide()

eg:
$('.tab:not(.aboutus)').hide(500);
.
.
.
$(thisAd).children('.tab').hide(500);
.
.
.

Open in new window


hide(500) is the same as saying: this control will hide and the effect will take 500miliseconds;    
- 1000miliseconds = 1 second
0
 
UName10Author Commented:
This is the updated effect and this is what I'd like it to be on this page here.

This is the current code:

$(window).load(function(){
	
	$('.tab:not(.aboutus)').fadeOut();

	
	$('.tabs li').click(function(){
		var thisAd = $(this).parent().parent();
		$(thisAd).children('.tab').fadeOut();
		$(thisAd).children('.'+$(this).attr('class').replace('tab','')).fadeIn();
		$('.tabs li').removeClass('active');												 	
		$(this).addClass('active');
	});

                newContent.hide();
                currentContent.fadeOut(10, function() {
                    newContent.fadeIn(100);
                    currentContent.removeClass('current-content');
                    newContent.addClass('current-content');
                });

	if(window.location.hash) {
		if (window.location.hash == "#map") {
			$(".Advert").children('.tab').fadeOut();
			$(".Advert").children('.map').fadeIn();
			$('.tabs li').removeClass('active');												 	
			$('.maptab').addClass('active');
		}
		if (window.location.hash == "#voucher") {
			$(".Advert").children('.tab').fadeOut();
			$(".Advert").children('.vouchers').fadeIn();
		}
	}	
	
});

Open in new window


The fade effect isn't very good, the last 2 tabs are jittery and not seamless..
0
 
APoPhySptCommented:
Are you running the last jquery version ? did you try the .hide(600) and .show(600)
0
 
UName10Author Commented:
Hi just changed it to this, but it's got an odd effect now (especially the aboutus) tab...

$(window).load(function(){
	
	$('.tab:not(.aboutus)').hide(400);
	
	$('.tabs li').click(function(){
		var thisAd = $(this).parent().parent();
		$(thisAd).children('.tab').hide();
		$(thisAd).children('.'+$(this).attr('class').replace('tab','')).show(400);
		$('.tabs li').removeClass('active');												 	
		$(this).addClass('active');
	});

	
	if(window.location.hash) {
		if (window.location.hash == "#map") {
			$(".Advert").children('.tab').hide();
			$(".Advert").children('.map').show();
			$('.tabs li').removeClass('active');												 	
			$('.maptab').addClass('active');
		}
		if (window.location.hash == "#voucher") {
			$(".Advert").children('.tab').hide();
			$(".Advert").children('.vouchers').show();
		}
	}	
	
});

Open in new window


Thanks again..
0
 
APoPhySptCommented:
try replacing

$('.tab:not(.aboutus)').hide(400);
with:
$('.tab:not(.aboutus)').slideDown(600);
0
 
UName10Author Commented:
Same effect I'm afraid... Don't know why it's not working either!
0
 
UName10Author Commented:
fsb\f
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now