javascript - Reverse animation on a second click -


i have submenu elements has on click, slide out spread out fill space. on second click i'd animation reverse before sliding in, jquery knowledge isn't enough achieve this. can please?

my js:

$('.box').click(function(){     var flag = $(this).data('flag');      $('.tab1').toggle("slide", { direction: "left"}, 500);     $('.tab2').toggle("slide", { direction: "left" }, 500);     $('.tab3').toggle("slide", { direction: "left" }, 500);      $('.tab1').animate({top: (flag ? '+=50px' : '-=50px')});      $('.tab3').animate({top: (flag ? '-=50px' : '+=50px')});          $(this).data('flag', !flag) }); 

jsfiddle

the animations element run after previous 1 has finished, @ moment left slides run , when has finished, vertical animation kicks in.

when flag true, want vertical animation run first. need vertical animation first.

the other issue not animating .tab2 in vertical animation, starts shrinking , looks odd. can around animating 0px during vertical animation, wait until correct time shrink:

$('.box').click(function(){      var flag = $(this).data('flag');            if(flag) {          $('.tab1').animate({top: '+=50px'});          $('.tab3').animate({top: '-=50px'});          $('.tab2').animate({top: '+=0px'});      }            $('.tab1, .tab2, .tab3').toggle("slide", { direction: "left"}, 500);            if(!flag) {          $('.tab1').animate({top: '-=50px'});          $('.tab3').animate({top: '+=50px'});      }            $(this).data('flag', !flag)  });
.square{      margin-left:100px;  }  .box{      position:relative;      width:150px;      height:150px;      background-color:transparent;      color:#fff;      text-align:center;         }  .tab4{     position:absolute;      right:10px;      top:50px;          width:70px;      height:40px;      background-color:grey;  }  .tab{      width:70px;      height:40px;      background-color:grey;      display:none;  }  .tab1{     position:absolute;      right:-70px;      top:50px;  }  .tab2{     position:absolute;      right:-70px;      top:50px;  }    .tab3{     position:absolute;      right:-70px;      top:50px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>  <div class="square">      <div class="box">          <div class="tab4">click</div>                    <div class="tab1 tab"></div>          <div class="tab2 tab"></div>          <div class="tab3 tab"></div>      </div>  </div>


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -