<!-- Меню второго уровня из Zero-блока по клику или наведению | https://necodim.ru/tilda/menu-sub -->
<style> .uc-menu {
position: absolute;
top: 0;
left: 0;
z-index: 999999;
width: 100%;
}
.uc-menu-sub .t396__artboard {
position: absolute;
top: 80px;
left: 0;
z-index: 999998;
opacity: 0;
pointer-events: none;
transform: translateY(-2000px);
transition: opacity .2s ease-in;
}
.uc-menu-sub .t396__artboard.active {
pointer-events: all !important;
transform: translateY(0px) !important;
opacity: 1;
}
.menu-btn.active .tn-atom {
color: #222222 !important;
background-color: #ffcc00 !important;
border-color: #ffcc00 !important;
}
</style>
<script>
$(function() {
let menu = $('.uc-menu'),
menuBtn = menu.find('.menu-btn'),
menuBtnLink = '#menu',
menuSub = $('.uc-menu-sub'),
menuSubArtboard = menuSub.find('.t396__artboard'),
menuSubWrapper;
for (let i=0; i<menuSub.length; i++) {
$(menuSub[i]).find('.t396__elem').wrapAll('<div class="menu-sub">');
}
menuSubWrapper = $('.menu-sub');
function menuSubOpen(e) {
e.preventDefault();
menuBtn.removeClass('active');
menuSubArtboard.removeClass('active');
let n = parseInt($(e.target).attr('href').replace(menuBtnLink, ''), 10) - 1;
$(menuBtn[n]).addClass('active');
$(menuSub[n]).find('.t396__artboard').addClass('active');
t_lazyload_update();
}
function menuSubClose(e) {
e.preventDefault();
menuBtn.removeClass('active');
menuSubArtboard.removeClass('active');
}
function menuSubToggle(e) {
e.preventDefault();
menuBtn.hasClass('active') ? menuSubClose(e) : menuSubOpen(e);
}
menuBtn.click(e => menuSubToggle(e));
menuSubWrapper.mouseleave(e => menuSubClose(e));
menuSubArtboard.mouseleave(e => menuSubClose(e));
$(window).scroll(e => menuSubClose(e));
});
</script>