如何结合这两个脚本?

时间:2020-07-02 17:17:57

标签: javascript jquery menu toggle

我要使用-x.classList.toggle("change")myNav.style.height = "0px"

任何建议。这是我的2个脚本

<script>   
    function toggleNav() {
        var element = document.getElementById("myNav");
        if (element.style.height == "300px") {
        element.style.height = "0px";
        } else {
        element.style.height = "300px";
        }
    }
    function myFunction(x) {
        x.classList.toggle("change");
    }
    </script>
    
    <script>
    window.addEventListener('mouseup', function(event){
        var myNav = document.getElementById('myNav');
        if (event.target != myNav && event.target.parentNode != myNav){
        myNav.style.height = "0px";
        }
    });
    </script>

0 个答案:

没有答案