从悬停到单击wordpress菜单

时间:2018-05-07 14:07:49

标签: javascript jquery wordpress navigationbar

我使用了一个我改变的主题,现在我想显示子菜单onClick而不是悬停,我不擅长javascript,但我认为这段代码与导航菜单有关:

//top menu works only on 1 level, the other submenus are hidden from css
//on tablets, wide level 3 submenus may go out of screen

var tdMenu = {};
(function(){
    'use strict';

    tdMenu = {

        //submenu items (used on unbind)
        _itemsWithSubmenu: null,
        //main menu (used on unbind)
        _mainMenu: null,

        //on touch - when you click outside the menu it will close all menus
        _outsideClickArea: null,
        _outsideClickExcludedAreas: '#td-header-menu .sf-menu, #td-header-menu .sf-menu *, .menu-top-container, .menu-top-container *',

        //added when menu is open
        _openMenuClass: 'sfHover',
        _openMenuBodyClass: 'td-open-menu',



        /*
         * initialize menu
         */
        init: function() {
            //get menu items
            var mainMenu = jQuery('#td-header-menu .sf-menu'),
                menus = jQuery('#td-header-menu .sf-menu, .top-header-menu'),
                menuLinks = menus.find('.menu-item-has-children > a, .td-mega-menu > a');

            //add dropdown arrow on items with submenu
            menuLinks.append('<i class="td-icon-menu-down"></i>');

            //main menu width adjustment (top menu will use css)
            mainMenu.supersubs({
                minWidth: 10, // minimum width of sub-menus in em units
                maxWidth: 20, // maximum width of sub-menus in em units
                extraWidth: 1 // extra width can ensure lines don't sometimes turn over
            });

            //add sf-with-ul class to all anchors
            menuLinks.addClass('sf-with-ul');
            //add sf-js-enabled class
            menus.addClass('sf-js-enabled');
            //hide all submenus
            menuLinks.parent().find('ul').first().css('display', 'none');

            //set unbind items
            tdMenu._mainMenu = mainMenu;
            tdMenu._itemsWithSubmenu = menuLinks;
            tdMenu._outsideClickArea = jQuery(window).not(tdMenu._outsideClickExcludedAreas);
            //initialize menu
            tdMenu._setHover(menuLinks, mainMenu);
        },

如何更改为onclick? 我不是很擅长Javascript

1 个答案:

答案 0 :(得分:0)

尝试改变:

tdMenu._setHover(menuLinks, mainMenu);

进入:

tdMenu._setOnClick(menuLinks, mainMenu);

或类似的东西,你可以尝试在主题库中找到正确的方法