Back Menu JS
============================== ============================= BACK MENU JS (WITH SMOOTHNESS) ============================== =============================
============================== ========= JS DEPARTMENT ============================== =========
<script>
$(function() {
//===== Add js-enabled class in body
$('.custom-menu-primary'). addClass('js-enabled');
//========= add mobile-trigger
$('.custom-menu-primary'). after('<div class="mobile-trigger">Menu</ div>');
//========= add child-trigger
$('.custom-menu-primary .flyouts .hs-item-has-children > a').after(' <div class="child-trigger"><i></i>< /div>');
//========= wrap custom-menu-primary with a div
$('.custom-menu-primary'). wrapInner('<div class="inner-menu-section"></ div>');
//========= add back menu in each sub menu section
$('.custom-menu-primary .hs-menu-wrapper > ul ul').prepend('<li class="dl-back"><a href="javascript:void(0);"> Back</a></li>');
//======== add seprate class in each li
$('.custom-menu-primary .hs-menu-wrapper > ul li').each(function() {
$(this).addClass($(this). children('a').text().split(" ").join('-').toLowerCase(). replace("?", ""));
});
//========= add mobile-open class in body on click of mobile-trigger
$('.mobile-trigger').click( function() {
$('body').toggleClass('mobile- open');
setTimeout (function(){
$('.custom-menu-primary .hs-menu-wrapper > ul li').removeClass(' unActiveMenu').removeClass(' activeMenu');
$('.custom-menu-primary'). removeClass('active-menu');
$('.inner-menu-section'). removeClass('level-1'). removeClass('level-2'). removeClass('level-3'). removeClass('level-4'). removeClass('level-5');
}, 300);
return false;
});
//========= remove mobile-open class on body click
$('body').click(function() {
$('body').removeClass('mobile- open');
});
$('.mobile-trigger,.custom- menu-primary').click(function( e) {
e.stopPropagation();
});
//======== child trigger click function
$('.child-trigger').click( function() {
$(this).parent('li'). removeClass('unActiveMenu'). addClass('activeMenu');
var currentThis = $(this);
setTimeout(function() {
currentThis.parent('li'). siblings().removeClass(' activeMenu').addClass(' unActiveMenu');
}, 300);
if ($(this).parent().hasClass(' hs-menu-depth-1')) {
$('.inner-menu-section'). addClass('level-1');
$('.custom-menu-primary'). addClass('active-menu');
}
if ($(this).parent().hasClass(' hs-menu-depth-2')) {
$('.inner-menu-section'). addClass('level-2');
}
if ($(this).parent().hasClass(' hs-menu-depth-3')) {
$('.inner-menu-section'). addClass('level-3');
}
if ($(this).parent().hasClass(' hs-menu-depth-4')) {
$('.inner-menu-section'). addClass('level-4');
}
if ($(this).parent().hasClass(' hs-menu-depth-5')) {
$('.inner-menu-section'). addClass('level-5');
}
});
//======== back menu click function
$('.dl-back').click(function() {
$(this).parent().parent(). siblings().removeClass(' unActiveMenu');
var currentThis = $(this);
setTimeout(function() {
currentThis.parent().parent(). removeClass('activeMenu');
}, 300);
if ($(this).siblings().hasClass(' hs-menu-depth-2')) {
$('.inner-menu-section'). removeClass('level-1');
$('.custom-menu-primary'). removeClass('active-menu');
}
if ($(this).siblings().hasClass(' hs-menu-depth-3')) {
$('.inner-menu-section'). removeClass('level-2');
}
if ($(this).siblings().hasClass(' hs-menu-depth-4')) {
$('.inner-menu-section'). removeClass('level-3');
}
if ($(this).siblings().hasClass(' hs-menu-depth-5')) {
$('.inner-menu-section'). removeClass('level-4');
}
if ($(this).siblings().hasClass(' hs-menu-depth-6')) {
$('.inner-menu-section'). removeClass('level-5');
}
});
//========= Add parent link in child section (optional part)
$('.dl-back').each(function() {
var currentText = $(this).parent().siblings('a') .text();
var currentLink = $(this).parent().siblings('a') .attr('href');
$(this).after('<li class="parent-link"><a href="' + currentLink + '">' + currentText + '</a></li>');
});
});
</script>
============================== ========= CSS DEPARTMENT ============================== =========
<style>
@media (min-width:768px){
.custom-menu-primary li.dl-back,
.custom-menu-primary li.parent-link{
display: none !important;
}
}
@media (max-width:767px){
.header-container-wrapper, .body-container-wrapper, .footer-container-wrapper {
position: relative;
left: 0;
transition: all .3s ease-in-out;
}
.mobile-open .header-container-wrapper, .mobile-open .body-container-wrapper, .mobile-open .footer-container-wrapper {
left:-250px
}
.custom-menu-primary{
position: fixed;
padding-top: 0;
/* Makes room for button */
margin: 0;
top:0;
right:-250px;
background: #f5f5f5;
width: 250px !important;
height: 100%;
transition: all .3s ease-in-out;
z-index: 999;
overflow: auto;
overflow-x: hidden;
}
.mobile-open .custom-menu-primary{
right:0;
}
.child-trigger{
display: block !important;
/* Hide button on Desktop */
cursor: pointer;
/* Mouse pointer type on hover */
position: relative;
z-index:1;
width: 100% !important;
/* Button width */
height: 45px !important;
/* Button height */
padding: 0 !important;
margin-top: -45px;
}
.custom-menu-primary .hs-menu-wrapper > ul li{
position:static !important;
}
.custom-menu-primary .hs-menu-wrapper.hs-menu-flow- horizontal>ul li.hs-item-has-children ul.hs-menu-children-wrapper {
position: absolute !important;
top: 0;
left: 100%;
display: block;
padding: 0;
}
.custom-menu-primary .hs-menu-wrapper > ul ul li.dl-back > a {
text-indent: 30px !important;
background: #f5f5f5 !important;
}
.custom-menu-primary .hs-menu-wrapper > ul ul li.dl-back > a:after {
content: '';
background: url(//cdn2.hubspot.net/hubfs/ 4144101/Fairtrade%20May2018% 20Theme/Images/arrow-back- grey.png) no-repeat 0 0;
position: absolute;
left: 25px;
top: 50%;
margin-top: -4px;
width: 6px;
height: 8px;
}
.custom-menu-primary .hs-menu-wrapper > ul li.parent-link > a {
color: #000 !important;
}
.custom-menu-primary .hs-menu-wrapper > ul ul {
display: none !important;
}
.custom-menu-primary .hs-menu-wrapper > ul .unActiveMenu{
display: none !important;
}
.custom-menu-primary .hs-menu-wrapper > ul .unActiveMenu > ul.hs-menu-children-wrapper {
display: none !important;
}
.custom-menu-primary .hs-menu-wrapper > ul .activeMenu > ul.hs-menu-children-wrapper {
display: block !important;
}
.inner-menu-section{
position:relative;
transition:all 0.3s ease-in-out;
left:0;
}
.inner-menu-section.level-1 {
left: -250px;
}
.inner-menu-section.level-1. level-2 {
left: -500px;
}
.inner-menu-section.level-1. level-2.level-3 {
left: -750px;
}
.inner-menu-section.level-1. level-2.level-3.level-4 {
left: -1000px;
}
.inner-menu-section.level-1. level-2.level-3.level-4.level- 5 {
left: -1250px;
}
}
</style>
IF any query regarding contact -- Vishal Gaurav
Comments
Post a Comment