简体   繁体   English

第二次单击菜单切换不起作用

[英]Second click on menu toggle doesn't work

First click to open the menu works fine but the second one just doesn't work. 第一次单击以打开菜单,但第二个菜单不起作用。 I'm not a coder myself but I'm always trying to fix things myself. 我本人不是编码员,但我总是想自己解决问题。 I have searched a lot for answers but I'm not even close to solve this. 我已经搜寻了很多答案,但我什至无法解决。 Your help would be very much appreciated 非常感谢您的帮助

HTML 的HTML

About Services Clients Contact 关于服务客户联系
function openbox(){
        var d = document.getElementById("centralboxdiv");
        d.classList.remove("fadeOut");
        d.classList.remove("animated");
        d.className += " fadeIn animated";
        d.style.display = "flex";
        var d2 = document.getElementById("masthead"); 
        d2.style.display = "none";
        var d3 = document.getElementById("maincenterlogo"); 
        d3.style.display = "none";

        var d4 = document.getElementById("tempdcenterlogosmall");
        d4.classList.remove("fadeInUp");
        d4.classList.remove("animated");
        var d5 = document.getElementById("maincenterlogo");
        d5.classList.remove("fadeOutUp");
        d5.classList.remove("animated");
    }
    function closebox(){
        var d = document.getElementById("centralboxdiv");
        d.classList.remove("fadeIn");
        //d.classList.remove("animated");
        d.className += " fadeOut ";

        var d2 = document.getElementById("masthead"); 
        d2.style.display = "flex";
        var d3 = document.getElementById("maincenterlogo"); 
        d3.style.display = "flex";
        //d.style.display = "none";
    }

Javascript Java脚本

 function openbox(){ var d = document.getElementById("centralboxdiv"); d.classList.remove("fadeOut"); d.classList.remove("animated"); d.className += " fadeIn animated"; d.style.display = "flex"; var d2 = document.getElementById("masthead"); d2.style.display = "none"; var d3 = document.getElementById("maincenterlogo"); d3.style.display = "none"; var d4 = document.getElementById("tempdcenterlogosmall"); d4.classList.remove("fadeInUp"); d4.classList.remove("animated"); var d5 = document.getElementById("maincenterlogo"); d5.classList.remove("fadeOutUp"); d5.classList.remove("animated"); } function closebox(){ var d = document.getElementById("centralboxdiv"); d.classList.remove("fadeIn"); //d.classList.remove("animated"); d.className += " fadeOut "; var d2 = document.getElementById("masthead"); d2.style.display = "flex"; var d3 = document.getElementById("maincenterlogo"); d3.style.display = "flex"; //d.style.display = "none"; } 

Thank you 谢谢

It seems that in your HTML the menu toggle never gets a chance to call closebox function. 似乎在HTML中,菜单切换永远不会有机会调用closebox函数。

I suggest you to use a single toggle function (like the one in jQuery) to handle the toggle action, or some CSS trick. 我建议您使用单个切换功能(如jQuery中的切换功能)来处理切换操作或一些CSS技巧。

If you insist on using one open function and one close function, you can try addEventListener . 如果您坚持使用一个打开功能和一个关闭功能,则可以尝试addEventListener

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

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