ハンバーガーメニューをjQeuryで実装中なのですが、ハンバーガーメニューをクリックしてもfadeToggleメソッドで表示されません。また、display:noneせず表示したときに要素の上下関係がおかしくなり、見出しがメニューより上にきてしまいます。
この二点をどうかご教授ください。
コード ```HTML <!doctype html> <html lang="ja"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> --> <link rel="stylesheet" href="css/reset.css"> <link rel="stylesheet" type="text/css" href="css/style.css"> <link href="https://use.fontawesome.com/releases/v5.15.1/css/all.css" rel="stylesheet"> <title>Shiro</title> </head> <body> <div class="bg"> <header class="header"> <div class="container header-inner"> <h1 class="header-logo"><a href="#">Shiro</a></h1> <div class="burger-btn"><!-- ③ハンバーガーボタン --> <span class="bar bar_top"></span> <span class="bar bar_mid"></span> <span class="bar bar_bottom"></span> </div> </div> <nav class="header-nav"> <ul class="header-menu"> <li><a href="#">Concept</a></li> <li><a href="#">Work</a></li> <li><a href="#">Florist</a></li> <li><a href="#">Shopinfo</a></li> <li><a href="#">Contact us</a></li> </ul> </nav> </div> </header> <div class="mv"> <h2 class="mv-ttl">Shiro</h2> <p class="mv-subttl">- White flower shop -</p> </div> </div> css body { font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif; } a { text-decoration: none; color: #333; } img { max-width: 100%; height: auto; } .container { max-width: 960px; margin: 0 auto; } .bg { height: 620px; background: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2)), url(../img/header.png); background-size: cover; position: relative; margin-bottom: 80px; } @media (max-width: 768px) { .txt-br { display: none; } } .padd-120 { margin-top: 120px; } @media (max-width: 768px) { .padd-120 { margin-top: 0; } } .header { height: 64px; padding-top: 40px; position: fixed; top: 0; left: 0; right: 0; } .header-logo a { font-size: 36px; color: #fff; } .header-inner { height: 100%; display: flex; justify-content: space-between; align-items: center; } .header-inner i { color: white; } @media (max-width: 768px) { .header-inner { width: 90%; } } .header-nav { display: none; position: fixed; background-color: white; text-align: center; color: #000; font-size: 18px; line-height: 11vh; z-index: 99; opacity: 0.8; height: calc(100vh - 64px); width: 100vw; } .header li { border: solid 1px #ccc; } .header-menu a:hover { text-decoration: underline; } .burger-btn { display: block; width: 39px; height: 39px; position: relative; z-index: 3; border: none; } .bar { width: 20px; height: 1px; display: block; position: absolute; left: 50%; transform: translateX(-50%); background-color: #fff; } .bar_top { top: 10px; } .bar_mid { top: 50%; transform: translate(-50%, -50%); } .bar_bottom { bottom: 10px; } .burger-btn.close .bar_top { transform: translate(-50%, 10px) rotate(45deg); transition: transform .3s; } .burger-btn.close .bar_mid { opacity: 0; transition: opacity .3s; } .burger-btn.close .bar_bottom { transform: translate(-50%, -8px) rotate(-45deg); transition: transform .3s; } .mv { color: #fff; position: absolute; z-index: 0; bottom: 0; top: 50%; left: 50%; -webkit-transform: translate(-50%, -30%); transform: translate(-50%, -30%); } .mv-ttl { font-size: 120px; line-height: 1.4; } @media (max-width: 768px) { .mv-ttl { font-size: 110px; } } .mv-subttl { font-size: 16px; text-align: center; } .concept { text-align: center; width: 100%; background: linear-gradient(#fff 70%, #ededed 30%); padding-bottom: 80px; margin-bottom: 80px; } @media (max-width: 768px) { .concept { margin-bottom: 40px; } .concept .container { width: 90%; margin: 0 auto; } .concept-img img { object-fit: cover; height: 400px; margin-bottom: 16px; } } .concept-ttl { font-size: 36px; margin-bottom: 32px; padding-bottom: 24px; } .concept-ttl::after { content: ''; position: absolute; bottom: 0; left: 50%; width: 40px; height: 1px; background: #2b2b2b; transform: translateX(-50%); } .concept-txt { font-size: 16px; line-height: 1.4; margin-bottom: 40px; } @media (max-width: 768px) { .concept-txt { text-align: left; } } @media (max-width: 768px) { .concept-txt-br { display: none; } } .work { text-align: center; width: 100%; } @media (max-width: 768px) { .work { padding: 0; width: 90%; margin: 0 auto; } } .work-ttl { font-size: 36px; position: relative; margin-bottom: 32px; padding-bottom: 24px; } .work-ttl::after { content: ''; position: absolute; bottom: 0; left: 50%; width: 40px; height: 1px; background: #2b2b2b; transform: translateX(-50%); } .work-txt { font-size: 16px; line-height: 1.4; margin-bottom: 40px; } @media (max-width: 768px) { .work-txt { text-align: left; } } .work-contents-box { display: flex; flex-wrap: wrap; flex-direction: column; align-content: space-between; height: 1680px; } @media (max-width: 768px) { .work-contents-box { flex-direction: row; margin-bottom: 20px; max-width: 400px; margin-left: auto; margin-right: auto; height: auto; } } .work-content-box { width: 420px; } .work-box { margin-bottom: 80px; } .work-box-ttl { font-size: 24px; font-weight: bold; line-height: 1.7; } .work-box-txt { line-height: 1.4; } .florist { text-align: center; width: 100%; background: linear-gradient(#ededed 60%, #fff 40%); padding-top: 40px; margin-bottom: 120px; } @media (max-width: 768px) { .florist { width: 90%; margin-left: auto; margin-right: auto; } } .florist-ttl { font-size: 36px; position: relative; margin-bottom: 32px; padding-bottom: 24px; } .florist-ttl::after { content: ''; position: absolute; bottom: 0; left: 50%; width: 40px; height: 1px; background: #2b2b2b; transform: translateX(-50%); } .florist-txt { font-size: 16px; line-height: 1.4; margin-bottom: 40px; } .florist-name { font-size: 24px; font-weight: bold; line-height: 1.7; } .florist-content-box { width: calc(33.33333333% - 25px * 2 / 3); margin-right: 30px; text-align: left; } @media (max-width: 768px) { .florist-content-box { width: 100%; text-align: center; margin-right: auto; margin-left: auto; } } .florist-contents-box { display: flex; } @media (max-width: 768px) { .florist-contents-box { flex-direction: column; } } .headerColorScroll { background-color: white; box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16); z-index: 999; } js $(function () { $(window).on("scroll", function () { const sliderHeight = 640; if (sliderHeight - 30 < $(this).scrollTop()) { $(".header").addClass("headerColorScroll").css('padding-top','0'); $(".header-logo a").css("color",'#333'); $(".menu-btn i").css("color",'#333'); } else { $(".header").removeClass("headerColorScroll"); $(".header-logo a").css("color",'#fff'); $(".menu-btn i").css("color",'#fff'); } }); }); $('.burger-btn').on('click',function(){ $('.burger-btn').toggleClass('close'); $('.header-menu').fadeToggle(500); });
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。