Bootstrap切换崩溃怎么了?它不起作用

时间:2019-11-02 12:06:05

标签: jquery wordpress drop-down-menu bootstrap-4 slidetoggle

我在网站上使用WordPress,并由jQuery自己创建了一个主菜单,当用户单击菜单按钮时,该主菜单将为slideleft。但是有一个大问题:Bootstrap collapse在我自己的菜单中不起作用,我很困惑为什么?

实际上,我希望通过单击用户扩展菜单中的某个项目(slidedown),以显示更多项目。

jQuery(document).ready(function($) {

  $('#menubutton').click(function(e) {
    e.stopPropagation();
    $('#menuhidden').toggleClass('menushown');
  });
  $('#menuhidden').click(function(e) {
    e.stopPropagation();
  });
  $('body,html').click(function(e) {
    $('#menuhidden').removeClass('menushown');
  });


});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
  <div class="topmenubutton" id="menubutton">
    <span></span>
    <span></span>
    <span></span>
  </div>
  <div class="topmenusearch">
    <a href="#searchmodal" data-toggle="modal"><i class="fa fa-search"></i></a>
  </div>
  <div class="topmenuicon">
    <a href=""><img src="" class="img-responsive" alt=""></a>
  </div>
</header>

<nav id="menuhidden" class="menuhidden">

  <ul>
    <a href="">
      <li><i class="fa fa-home"></i><span>course01</span></li>
    </a>
    <a href="">
      <li><i class="fa fa-user"></i><span>course02</span></li>
    </a>
    <a href="">
      <li><i class="fa fa-phone"></i><span>course03</span></li>
    </a>

    <div class="panel-group">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4 class="panel-title">
            <a data-toggle="collapse" href="#menuitems" aria-expanded="false" aria-controls="collapse2">course04</a>
          </h4>
        </div>
        <div id="menuitems" class="panel-collapse collapse">
          <ul class="list-group">
            <a href="<?php echo site_url().'/downloads/category/download-course/'; ?>"></a>
            <a href="<?php echo site_url().'/downloads/category/download-course/'; ?>"></a>
          </ul>
        </div>
      </div>
    </div>

    <a href="">
      <li><i class="fa fa-home"></i><span>course05</span></li>
    </a>
    <a href="">
      <li><i class="fa fa-user"></i><span>course06</span></li>
    </a>
    <a href="">
      <li><i class="fa fa-phone"></i><span>course07</span></li>
    </a>
  </ul>

</nav>

1 个答案:

答案 0 :(得分:0)

我真的不明白,原因是什么,JQuery无法解决问题,但CSS却满足了我的要求。我在主菜单中制作了手风琴:

<div class="acorcss">   
                        <div class="tabs">
                          <div class="tab">
                            <input type="checkbox" id="chck1">
                            <label class="tab-label" for="chck1">دوره های سریالی</label>
                            <div class="tab-content">
                              <a href="<?php echo site_url().'/archive-towlid-mohtava/'; ?>"><li><span>صفر تا صد تولید محتوا</span></li></a>
                              <!--<a href="#"><li><span>دوره های آنلاین</span></li></a>-->
                            </div>
                          </div>
                        </div>
                </div>

CSS代码:

.acorcss {
    border-top: 1px solid #ddd;
    padding-top: 5px;
    margin-top: 5px;
}
.acorcss input {
  position: absolute;
  opacity: 0;
  z-index: -1;
}
/* Accordion styles */
.acorcss .tabs {
  overflow: hidden;
  /*box-shadow: 0 4px 4px -2px rgba(0,0,0,0.5);*/
}
.acorcss .tab {
  width: 100%;
  color: white;
  overflow: hidden;
}
.acorcss .tab-label {
    position: relative;
    display: flex;
    /* justify-content: space-between; */
    cursor: pointer;
    color: black;
    background: white;
    font-weight: normal;
    font-size: 13px;
    line-height: 36px;
}
/* Icon */
.acorcss .tab-label::after {
    content: "\276F";
    content: "\02795";
    transition: all .35s;
    position: absolute;
    left: 0;
    color: black;
    color: #696969;
}
.acorcss .tab:first-child .tab-label::before {
    content: "\f018";
    font-family: fontawesome;
    font-weight: normal;
    transition: all .35s;
    vertical-align: middle;
    font-size: 18px;
    margin-left: 10px;
    color: red;
}
.acorcss .tab-content {
    max-height: 0;
    padding-right: 10px;
    color: #2c3e50;
    background: white;
    transition: all .35s;
}
.acorcss .tab-content li {
    line-height: 26px;
}
.acorcss .tab-close {
    display: flex;
    justify-content: flex-end;
    padding: 1em;
    font-size: 0.75em;
    background: #2c3e50;
    cursor: pointer;
}
.acorcss .tab-close:hover {
      background: darken(#2c3e50, 10%);
}
.acorcss input:checked + .tab-label {
    background: #2c3e50;
    background: white;
    font-weight: bold;
}
.acorcss input:checked + .tab-label::after {
    /*transform: rotate(90deg);*/
    content: "\2796";
}

.acorcss input:checked ~ .tab-content {
    max-height: 100vh;
    padding: 0 20px 10px 0;
    padding: 0 10px 10px 0;
}