简体   繁体   English

响应式导航菜单:(使用 html 和 Css)切换菜单不起作用

[英]responsive navigation menu : ( using html and Css ) Toggle menu not working

I am working on a simple navigation menu on building a ecommerce site.我正在开发一个用于构建电子商务网站的简单导航菜单。 I want the menu to be responsive when I re-size the window less than 800 px but the toggle menu is not working its not disappearing when I touch the menu icon, the options are already showing and not disappearing当我将 window 的大小重新调整为小于 800 像素时,我希望菜单能够响应,但是当我触摸菜单图标时,切换菜单不起作用,它不会消失,选项已经显示并且不会消失

#here is the link to my code https://github.com/roshini004/ecommerce-site.git #这里是我的代码https://github.com/roshini004/ecommerce-site.git的链接

Firstly, in Javascript, we tend not to start variables with capital letters like MenuItems;首先,在 Javascript 中,我们不倾向于像 MenuItems 那样以大写字母开头的变量; it might mess up some OOP things in JS and sometimes autocomplete might mix it up.它可能会在 JS 中弄乱一些 OOP 的东西,有时自动完成可能会混淆它。

But in this case, you need to camel case css styles in javascript.但是在这种情况下,你需要在javascript中驼峰式css styles。 (maxHeight, not maxheight) (最大高度,不是最大高度)

var MenuItems = document.getElementById("MenuItems");

MenuItems.style.maxHeight = "0px";

function menutoggle() {
    console.log("clicked");
    if(MenuItems.style.maxHeight == "0px")
        {
        MenuItems.style.maxHeight = "200px";
    }
    else
    {
        MenuItems.style.maxHeight = "0px";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM