jquery - Cannot finish dropdown menu -
so have spent lot of time on , have got final part , cannot seem make dropdown function.
i using jquery hover. hover on main link, sub links appear , content moves down, hover on sublink has children , sub sublinks appear , content moves down more when hover on sub sub link, content shifts sub sub links remain visible under it.
i have few theories may me through this, 1 of use sub function instead of 2 different ones. use case statement move content have feeling if streamline code may end fixing problem also.
here jquery:
$(document).ready(function () { $(".main-menu-link").hover(function () { $(".main-menu-link").removeclass("active"); $(this).addclass("active"); //$(".menu-depth-1").hide(); $(this).parent().siblings().children('ul').hide(); // $(this).siblings(".menu-depth-1").fadein(); if ($(this).siblings('ul').is(":visible")) { $("#index-content").animate({ 'margin-top': 46 }); alert('doh'); } else { $("#index-content").animate({ 'margin-top': 10 }); } }); $(".sub-menu-link").hover(function () { $(".sub-menu-link").removeclass("active"); $(this).addclass("active"); $(this).parent().siblings().children('ul').hide(); $(this).siblings(".menu-depth-2").fadein(); if ($(this).siblings('ul').is(":visible")) { $("#index-content").animate({ 'margin-top': 92 }); } else { $("#index-content").animate({ 'margin-top': 46 }); } }); }); and here jsfiddle:
thanks , reading.
c
$(".sub-menu-link").hover(function () { this line reason why sub-sub-links cause content move up, because both sub-links , sub-sub-links trigger hover function.
$(".sub-menu-link").hover(function () { $(".sub-menu-link").removeclass("active"); $(this).addclass("active"); // added following line: $(this).siblings().find('.sub-menu-link').off('mouseenter mouseleave'); $(this).parent().siblings().children('ul').hide(); $(this).siblings(".menu-depth-2").fadein(); if ($(this).siblings('ul').is(":visible")) { $("#index-content").animate({ 'margin-top': 92 }); } else { $("#index-content").animate({ 'margin-top': 46 }); } }); with line of code added, removes hover function sub-sub-links when parent sub-links first hovered.
alternatively, use class name instead of class="sub-menu-link" sub-sub-links.
note solution tackles problem found @ level of sub-sub-links. if there need deeper lists of links i.e. sub-sub-sub-links , sub-sub-sub-sub-links, creating "sub function", said, preferable.
Comments
Post a Comment