5
I have a menu with 3 levels vertically (similar to the globe.com), my problem is when I I am in the last item of the 2nd level(for example) and move the mouse to the 1st item of the 3rd level, Hover event in the 2nd level is activated and I miss the navigation not being able to reach the 3rd level level.
I need a solution similar to that of the globe, when I’m in the second level and I go to the 3rd, I need to set a time to reach the 3rd level.
My current script looks like this:
//manipula primeiro e segundo nivel
$("#main-menu ul > li.mn-item-li").mouseenter(function (e) {
var currentMenu = $(this);
if (currentMenu.hasClass('sub-menu')) {
currentMenu.find('.mn-item-a').addClass('active');
}
currentMenu.children('div').stop().show();
//seta item do menu mais-visto aberto como padrão
currentMenu.find('.second-nivel').find('li').eq(0).find('a').addClass('active');
$(".mn-maisvistos").css({ "visibility": "visible", "opacity": "1" });
//seta altura do subnivel
var heightSubnivel = currentMenu.find('.second-nivel').height();
var widthtSubnivel = currentMenu.find('.second-nivel').width();
currentMenu.find('.second-nivel').css({ 'height': heightSubnivel + 'px' });
currentMenu.find('.third-nivel').css({ 'height': heightSubnivel + 'px' });
//manipula segundo e terceiro nivel
var timer;
var teste = function () {
currentMenu.find('.second-nivel > li a').mouseenter(function () {
var dataSubNivel = $(this).data("menu-id");
var indexSubNivel = $(this).parent().index();
$('.second-nivel > li a').removeClass('active');
if ($(this).parent().hasClass("subnivel")) {
//console.info(indexSubNivel)
$('.third-nivel > li').css('visibility', 'hidden');
$(this).parents('.second-nivel').next().find("." + dataSubNivel).css({ 'visibility': 'visible', 'opacity': '1' });
$(this).addClass('active');
} else {
$('.third-nivel > li').css('visibility', 'hidden');
$(this).css("background-image", "none");
}
clearTimeout(timer);
})
}
currentMenu.find('.second-nivel > li a').mouseleave(function () {
$(this).off('mouseenter');
timer = setTimeout(function () { teste() }, 500);
});
currentMenu.find('.second-nivel > li a').mousemove(function (event) {
var pageCoords = "( " + event.pageX + ", " + event.pageY + " )";
var clientCoords = "( " + event.clientX + ", " + event.clientY + " )";
console.info("( event.pageX, event.pageY ) : " + pageCoords);
});
}).mouseleave(function () {
$(this).find('.third-nivel > li').css({ 'visibility': 'hidden', 'opacity': '0' });
$(this).find('.second-nivel li a').removeClass('active');
$(this).children("div").stop().hide();
$(this).find('.mn-item-a').removeClass('active');
});
Welcome! It’s possible to merge HTML so we can test with your code? ideally by making a jsFiddle (http://jsfiddle.net)
– Sergio
Welcome to Stackoverflow, please use jsfiddle.net and put your html and javascript code in it so we can use it to solve your problem, if you don’t know how to use jsFiddle, just edit your question and post your HTML code in it.
– Paulo Roberto Rosa