dio-v
10/8/2014 - 12:45 PM

hoverIntent Dio style delay on show hide submenu (nunes.nl)

hoverIntent Dio style delay on show hide submenu (nunes.nl)

    var ultimer = '';
    var hidetimer = '';
    var vDelay = 300;
    var vNav = 'ul.nav';
    $(document).on('click', function (event) {
        if (!$(event.target).closest(vNav).length) {
            $(vNav).find('.hover').removeClass('hover');
        }
    });
    $(vNav).each(function () {
        var vN = $(this);
        vN.find('li.hasUl').each(function () {
            var vT = $(this);
            vT.bind('mouseenter', function () {
                clearTimeout(ultimer);
                clearTimeout(hidetimer);
                gotoUl(vN, vT);
            }).bind('mouseleave', function () {
                hidetimer = setTimeout(function () {
                    vN.find('.hover').removeClass('hover');
                }, vDelay);
            });
        });
    });

    function gotoUl(vN,vT) {
        if (!vN.find('.hover').length) {
            vN.find('.hover').removeClass('hover');
            vT.addClass('hover');
        } else {
            ultimer = setTimeout(function () {
                vN.find('.hover').removeClass('hover');
                vT.addClass('hover');
            }, vDelay);
        }
    }