Js
menu bar mouse move
by 영감은어디에
2025. 2. 25.
// 메뉴 색상바
var $marker = $('<div class="marker"></div>').appendTo('.menu');
var $navitem = $('.menu > .menu-item');
var $current = $('.menu-item.current-menu-item');
if ($current.parents('.sub-menu').length) { // 2차 메뉴
$current = $current.closest('.menu-item-has-children');
}
function indicator($el) {
$marker.css({
left: $el.position().left + 20 + "px",
width: $el.outerWidth() - 40 + "px",
opacity: 1
});
}
if ($current.length) {
indicator($current);
}
$navitem.mouseenter(function() {
indicator($(this));
});
$(".menu").mouseleave(function() {
if ($current.length) {
indicator($current);
} else {
$marker.css({ opacity: 0, width: "0px" });
}
});