-2

Right now it works on hover. I need to make it work on click only so it works properly on a mobile device.

.nav needs to be #access, but I get lost after that. What do I change .nav to match up with my css which is from wordpress?

I'm trying to get http://webdesigntutsplus.s3.amazonaws.com/tuts/378_tessa/tessa-lt-dropdowns-21c7868/index.html to work with wordpress.

http://jsfiddle.net/scottbotkins/dbW2Q/

    var ww = document.body.clientWidth;

$(document).ready(function() {
    $(".nav li a").each(function() {
        if ($(this).next().length > 0) {
            $(this).addClass("parent");
        };
    })

    $(".toggleMenu").click(function(e) {
        e.preventDefault();
        $(this).toggleClass("active");
        $(".nav").toggle();
    });
    adjustMenu();
})

$(window).bind('resize orientationchange', function() {
    ww = document.body.clientWidth;
    adjustMenu();
});

var adjustMenu = function() {
    if (ww < 768) {
        $(".toggleMenu").css("display", "inline-block");
        if (!$(".toggleMenu").hasClass("active")) {
            $(".nav").hide();
        } else {
            $(".nav").show();
        }
        $(".nav li").unbind('mouseenter mouseleave');
        $(".nav li a.parent").unbind('click').bind('click', function(e) {
            // must be attached to anchor element to prevent bubbling
            e.preventDefault();
            $(this).parent("li").toggleClass("hover");
        });
    } 
    else if (ww >= 768) {
        $(".toggleMenu").css("display", "none");
        $(".nav").show();
        $(".nav li").removeClass("hover");
        $(".nav li a").unbind('click');
        $(".nav li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function() {
            // must be attached to li so that mouseleave is not triggered when hover over submenu
            $(this).toggleClass('hover');
        });
    }
}
4

1 回答 1

0

一个简单的解决方法就像删除

 #access ul li:hover > ul {
    display: block;
}

从 CSS 和

添加这个 jQuery 代码

$('#menu-navigation li').click(function(){
       $(this).find('.sub-menu').show();
        $(this).siblings().find('.sub-menu').hide();
});

您必须更改代码才能获得所需的内容。

于 2013-03-19T09:57:21.193 回答