質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

Q&A

1回答

1236閲覧

ハンバーガーメニューjQuery実装について

koki48

総合スコア3

jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

0グッド

0クリップ

投稿2021/03/27 13:12

編集2021/03/27 13:15

ハンバーガーメニューを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); });

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

$('.header-menu').fadeToggle(500);$('.header-nav').fadeToggle(500);

投稿2021/03/30 09:51

Lhankor_Mhy

総合スコア36115

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問