Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仅将响应菜单重写为css_Javascript_Css_Menu_Responsive Design - Fatal编程技术网

Javascript 仅将响应菜单重写为css

Javascript 仅将响应菜单重写为css,javascript,css,menu,responsive-design,Javascript,Css,Menu,Responsive Design,我有菜单: JSFIDLE HTML JS 问: 如何在没有JS的情况下进行悬停和toogle?对于多级别游戏,你可以试试这个 这是一个CSS唯一的示例,它向您展示了您所谈论的悬停效果 将鼠标悬停在“程序”链接上并选中它。 这种效果可以应用于HTML中的任何元素 CSS语法如下所示 Element_name:Hover{ // CSS code } 例如: img{ opacity:1; } img:hover{ opacity:0; } 上面的示例将使img在悬停时透明 如

我有菜单:

JSFIDLE HTML JS 问:
如何在没有JS的情况下进行悬停和toogle?

对于多级别游戏,你可以试试这个


这是一个CSS唯一的示例,它向您展示了您所谈论的悬停效果

将鼠标悬停在“程序”链接上并选中它。 这种效果可以应用于HTML中的任何元素

CSS语法如下所示

Element_name:Hover{
       // CSS code
}
例如:

img{
opacity:1;
}
img:hover{
opacity:0;
}
上面的示例将使img在悬停时透明

如何在没有JS的情况下进行悬停和旋转

您可以在CSS选择器中使用以下选项

要切换,只需应用display:none;对一个元素是否有效


纯CSS所不能做的是响应点击事件。你需要JS。你试过CSS转换吗?你试过:active和:hover吗?@HashemQolami我试过了,我收到了其他人的抱怨,为什么我把它放在jsfidle上而不是这里,所以他们必须点击线路,我感觉就像在两块巨大的风车石头中间。放过我我将在10分钟内将其放入jsfidle。@Ing.MichalHudak在复杂场景中,除了问题中的代码之外,添加一个jsfidle用于测试和演示通常是有用的。顺便说一句@MarcelGwerder你知道CTRL+C/CTRL+V是如何工作的吗?不要偷懒:是多层次的还是仅仅两层的?
var ww = document.body.clientWidth;

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

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

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

var adjustMenu = function() {
    if (ww < 640) {
        $(".toggleMenu").css("display", "inline-block");
        if (!$(".toggleMenu").hasClass("active")) {
            $(".menu").hide();
        } else {
            $(".menu").show();
        }
        $(".menu li").unbind('mouseenter mouseleave');
        $(".menu 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 >= 640) {
        $(".toggleMenu").css("display", "none");
        $(".menu").show();
        $(".menu li").removeClass("hover");
        $(".menu li a").unbind('click');
        $(".menu 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');
        });
    }
}
body {
background: #ccc;
font-family: helvetica, arial, serif;
font-size: 13px;
text-transform: uppercase;
text-align: center;
}
Element_name:Hover{
       // CSS code
}
img{
opacity:1;
}
img:hover{
opacity:0;
}