javascript - Need my jQuery tabs not to close when active and already open -
i using jquery script hide , reveal 4 div containers html content on page.
jquery:
$('.content-drawer').hide(); $('#tab1').show(); $('#calc').show(); $('.tab').click(function() { var $this = $(this); var target = $(this.rel); $this.closest('li').addclass('active focus'); // add classes closest li of clicked anchor $('.tab').not($this).closest('li').removeclass('active focus'); // remove classes non-clicked items $('.content-drawer').not(target).fadeout(); // slideup other contents target.delay(400).fadetoggle(); // toggle css3-mediaqueriesrrent content if (target.is(':visible')) { // if target visible remove active class $this.closest('li').removeclass('active'); } return false; });
html:
<div class="content-drawer" id="tab2"> <div class="sixcol"> <img src="css/img/books.png" alt=""> </div> <div class="sixcol last"> <article> <h2>from our family yours</h2> <p>sed posuere consectetur est @ lobortis. integer posuere erat ante venenatis dapibus posuere velit aliquet. nullam quis risus eget urna mollis ornare vel eu leo. duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem.</p> <a class="button fancy" href="#">learn more</a> </article> </div> </div>
the client takes issue on account of fact when click div open, closes leaving nothing on screen.
what need: open div not "closable" on click
one way can make sure have 1 div visible use :visible
selector jquery has. have modified code , added in when have click .tab
tag
$('.content-drawer').hide(); $('#tab1').show(); $('#calc').show(); $('.tab').click(function() { var $this = $(this); var target = $(this.rel); //get number of .tabs visible var visible = $('.tab').filter(":visible").length; //if 1 visible return before preforming actions if(visible === 1){ return; } $this.closest('li').addclass('active focus'); // add classes closest li of clicked anchor $('.tab').not($this).closest('li').removeclass('active focus'); // remove classes non-clicked items $('.content-drawer').not(target).fadeout(); // slideup other contents target.delay(400).fadetoggle(); // toggle css3-mediaqueriesrrent content if (target.is(':visible')) { // if target visible remove active class $this.closest('li').removeclass('active'); } return false; });
hope helps.
Comments
Post a Comment