javascript 汉堡菜单JQuery

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 汉堡菜单JQuery相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Hamburger-Menu-CSS</title>
    <link rel="stylesheet" href="style.css">

</head>


<body>
    <header>
        <nav class="menu">
            <label class="hamburger-menu" for="hamburger">
                        <div class="hamburder__line"></div>
                        <div class="hamburder__line"></div>
                        <div class="hamburder__line"></div>
                    </label>
            <ul class="menu__links">
                <li>
                    <a href="#"></a>Home</li>
                <li>
                    <a href="#"></a>Products</li>
                <li>
                    <a href="#"></a>About</li>
                <li>
                    <a href="#"></a>Contact Us</li>
                <li>
                    <a href="#"></a>Buy</li>
            </ul>
        </nav>
    </header>

    <div class="main"></div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="main.js"></script>
</body>

</html>
@import url('https://fonts.googleapis.com/css?family=Roboto');
body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Roboto', sans-serif;
}

header {
    background-color: rgb(65, 65, 65);
    height: auto;
    transition: all 1s
}

nav.menu {
    padding: 1rem;
}

.hamburder__line {
    width: 35px;
    height: 2px;
    background-color: #fff;
    margin: 8px 0;
}

ul.menu__links {
    margin: 0;
    list-style: none;
}

li {
    color: #fff;
    display: inline-block;
    margin-right: 3rem;
}

label.hamburger-menu {
    display: none
}

@media screen and (max-width:768px) {
    label.hamburger-menu {
        display: block;
    }
    ul.menu__links {
        display: none;
    }
    nav.menu {
        padding: 7px;
    }
    li.mobile {
        display: block;
        padding: 1rem;
        text-align: center;
        border-bottom: 1px solid #fff;
    }
}
$('label.hamburger-menu').on('click', function() {
    $('.menu__links').toggle(500);
    $('li').addClass('mobile')
})

以上是关于javascript 汉堡菜单JQuery的主要内容,如果未能解决你的问题,请参考以下文章

选择后如何关闭汉堡菜单? javascript

javascript 菜单汉堡动画

javascript 启动自定义菜单汉堡包

javascript 汉堡菜单

javascript js + html + css - 汉堡菜单

javascript 汉堡菜单