javascript - FadeIn / FadeOut glitch using basic jQuery Tabs -


i'm working on simple fadein / fadeout tab system using jquery, however, it's not smooth i'd be.

here demo see in action.

take @ demo. expected fade in , out of 1 another, if click through tab 1 > tab 2 > tab 3 tab 1, there strange fadein/out glitches along way.

any ideas how fix this? jquery is:

$(document).ready(function(){          $('ul.tabs').each(function(){              var $active, $content, $links = $(this).find('a');              $active = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);             $active.addclass('active');             $content = $($active.attr('href'));              $links.not($active).each(function () {                 $($(this).attr('href')).hide();             });              $(this).on('click', 'a', function(e){                  $active.removeclass('active');                 $content.fadeout("slow");                  $active = $(this);                 $content = $($(this).attr('href'));                  $active.addclass('active');                 $content.fadein("slow");                  e.preventdefault();             });         });      }); 

and html is:

<ul class="tabs">     <li><a href="#tab1">overview</a></li>     <li><a href="#tab2">sub nav 2</a></li>     <li><a href="#tab3">sub nav 3</a></li> </ul>  <div id="tab1">     <p>this test 1</p> </div> <div id="tab2">     <p>this test 2</p> </div> <div id="tab3">     <p>this test 3</p> </div> 

many pointers :-)

you need make code call once finished fading out. code execute fade in before fading out has completed. in order cascade call can provide function second parameter fadeout. function call after function has completed it's animation. in case provided anonymous function remaining code.

$content.fadeout("slow", function()                                  {                                      $active = $(c);                                      $content = $($(c).attr('href'));                                       $active.addclass('active');                                      $content.fadein("slow");                                  }); 

i've updated you're fiddle. correct code modificiations.

http://jsfiddle.net/r8yqv/


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -