I am using WordPress
for my website and I created a main menu by jQuery
myself that will be slideleft
when the user click on the menu button. but there is a big issue: Bootstrap collapse
does not work in my own menu and I am confused why?
In fact, I want to have an item in the menu to be extended (slidedown
) with clicking by user to show more items in.
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>
I really did not understand, what the reason was and I could not solve the problem by JQuery
but I made what I wanted by CSS
. I made an accordion in the main menu:
<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>
the CSS code:
.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;
}