使jQuery .show()和.hide()与UI效果并行运行

时间:2014-03-25 09:37:42

标签: jquery css jquery-ui slide

我试图在jquery中创建一个带滑动效果的漂亮菜单: http://jsfiddle.net/rXjMV/5/

$(".goBack").click(function() {
    $(this).parent().hide('slide', {
        direction: 'right'
    });
    $("#parentSidebar").show('slide', {
        direction: 'left'
    });
});
$(".sidebarMover").click(function() {
    var newmenu = $(this).attr('name');
    $(this).parent().hide('slide', {
        direction: 'left'
    });
    $("#" + newmenu + "Sidebar").show('slide', {
        direction: 'right'
    });
});

请注意,如果你点击橄榄球,菜单会向左滑动,而另一个则从右边开始,但它们会一个在另一个之下,而不是并排...

尝试过很多东西,显示:内联和使用带有jQuery队列的延迟(),但是我认为,problam是CSS,坚持jQuery ......任何想法?

1 个答案:

答案 0 :(得分:1)

添加        位置:绝对;宽度:100%; 在这样的容器中:

<div id="sideBar">
    <div id="sideHead">TICKET MENU</div>
    <hr id="sideHeadSeperator">
       <div class="sideItemContainer" id="parentSidebar" style="position:absolute;width:100%; ">
          <div class="sideItem sidebarMover" name="football">Football<i class="fa fa-caret-right"></i></div>
          <div class="sideItem sidebarMover" name="tennis">Tennis<i class="fa fa-caret-right"></i></div>
          <div class="sideItem">Rugby<i class="fa fa-caret-right"></i></div>
          <div class="sideItem">Basketball<i class="fa fa-caret-right"></i></div>
       </div>
       <div class="sideItemContainer" id="footballSidebar" style="display: none;position:absolute; ;width:100%;" >
          <div class="sideItem">Arsenal<i class="fa fa-caret-right"></i></div>
          <div class="sideItem">Chelsea<i class="fa fa-caret-right"></i></div>
          <div class="sideItem">Liverpool<i class="fa fa-caret-right"></i></div>
          <div class="sideItem">Manchester Utd<i class="fa fa-caret-right"></i></div>
          <div class="sideItem">Manchester City<i class="fa fa-caret-right"></i></div>
          <div class="goBack"><i class="fa fa-caret-left fa-inverse"></i> go back</div>
        </div>
        <div class="sideItemContainer" id="tennisSidebar" style="display: none;">
           <div class="sideItem">Wimbledon<i class="fa fa-caret-right"></i></div>
           <div class="sideItem">Rome Masters<i class="fa fa-caret-right"></i></div>
           <div class="sideItem">US Open<i class="fa fa-caret-right"></i></div>
           <div class="sideItem">Roland Garros<i class="fa fa-caret-right"></i></div>
           <div class="sideItem">Madrid Masters<i class="fa fa-caret-right"></i></div>
           <div class="goBack"><i class="fa fa-caret-left fa-inverse"></i> go back</div>
      </div>
</div>