javascript - 如何使菜单出现(从左侧)并在单击按钮时消失

标签 javascript jquery

<分区>

我已经创建了一个按钮和一个 ListView 菜单,我希望它在单击按钮时在按钮下方从左到右切换 - 它应该出现和消失。请帮忙。谢谢。

$('#menu').click(function () {
    if ($('#pageone').is(':visible')){
        $('#pageone').fadeOut();
    } else {
        $('#pageone').toggle('slide', {
            direction: 'left'
        }, 1000, function(){ 
            $('#pageone').fadeIn();
        });
    }
});

最佳答案

var isOpen =true;
function toggleMenu(){
 
  if(isOpen){
    $('#pageone').hide('slow');
    isOpen = false;
    }else{
       $('#pageone').show('slow');
       isOpen = true;
      }
    
    
}
#top
{
  clear:both;
  position:fixed;
  top:0;
  height:40%;
  width:100%;
  background-color:#DCDCDC;
  text-align:center;
}
#bottom
{
   clear:both;
   position:fixed;
   bottom:0;
   height:60%;
   width:100%;
   background-color:#ffc878;
   text-align:center;
}
#menu
{
   position:fixed;
   left:2%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div id="top">
    <h2>Knowledge Point</h2>
    <h2>Self Test</h2>
    <input type="submit" value="Submit" name="submit" class="btn btn-success">
    <button id="menu" onclick="toggleMenu()">☰</button>
</div>
<div id="bottom">
<div data-role="page" id="pageone" style="float:left;width :30%;">
  <div data-role="main" class="ui-content">
    <ul data-role="listview" data-inset="true">
      <li data-icon="plus"><a href="question.html">Add a new question</a></li>
    </ul>
  </div>
</div> 
<div id="question" style="float:right; width:70%;">
Testing Content
<br>
</div>
</div>

关于javascript - 如何使菜单出现(从左侧)并在单击按钮时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35082344/

相关文章:

javascript - Ionic 3 和 Angular 4 - 未捕获( promise 中): TypeError: Cannot read property 'title' of undefined

javascript - JS Canvas - 基于百分比的多色弧形边框

javascript - 查找类为 'x' 的元素,忽略类为 'x' 和其他类的元素

javascript - 如果我尝试在新选项卡中复制并粘贴 url,React Router 会给出 404

javascript - 在数据模板中选择嵌套数据单击

javascript - 如果 Internet Explorer 将打印页面大小调整为 60%

javascript - animate.css 并删除元素

jquery - 如何消除 Internet Explorer 9 中选择多个列表中所有选项的缓慢滚动

php - 如何从 3 X 15 数组中找到 1 X 15 数组?

jQuery 使用声明的位置对对象进行动画处理