Solved

Adding a fadeOut to tabs

Posted on 2013-05-15
10
109 Views
Last Modified: 2013-11-28
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
Comment
Question by:UName10
  • 5
  • 5
10 Comments
 
LVL 6

Expert Comment

by:APoPhySpt
ID: 39168729
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
 
LVL 6

Expert Comment

by:APoPhySpt
ID: 39168738
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
 

Author Comment

by:UName10
ID: 39168838
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
 
LVL 6

Expert Comment

by:APoPhySpt
ID: 39168861
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
 

Author Comment

by:UName10
ID: 39168872
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 6

Expert Comment

by:APoPhySpt
ID: 39170626
Are you running the last jquery version ? did you try the .hide(600) and .show(600)
0
 

Author Comment

by:UName10
ID: 39171223
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
 
LVL 6

Expert Comment

by:APoPhySpt
ID: 39171307
try replacing

$('.tab:not(.aboutus)').hide(400);
with:
$('.tab:not(.aboutus)').slideDown(600);
0
 

Accepted Solution

by:
UName10 earned 0 total points
ID: 39171325
Same effect I'm afraid... Don't know why it's not working either!
0
 

Author Closing Comment

by:UName10
ID: 39683124
fsb\f
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now