Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good morning

Center sub menu navigation under parent

jQuerySnippets

About a 1 minute read

"Life is like riding a bicycle. To keep your balance, you must keep moving."

Albert Einstein


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$(document).ready(function (){                
    $('#menu-main > li').hover(
    function(){
        $subMenu = $(this).children('#menu-main > li > .sub-menu');
        $B = $(this).width();
        $A = $(this).children('#menu-main > li > .sub-menu').width();
        $C = ($A - $B);
        $D = $C/2;
        $(this).children('#menu-main > li > .sub-menu').dequeue().stop().show().css({'marginLeft': -$D + 'px'});   
        //console.log($D + 'px');  
    },
    function(){
        $(this).children('#menu-main > li > .sub-menu').dequeue().stop().hide();
    });
});