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

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

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

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

0回答

364閲覧

単一1ページのホームページで 同一ページ内リンクでハンバーガーメニューが閉じない

yoshi73

総合スコア0

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

1クリップ

投稿2022/09/23 04:20

前提

単一の1ページのホームページで
同一ページ内リンクでハンバーガーメニューが閉じない

実現したいこと

ハンバーガーメニューをクリックし、メニューを押すと、同一ページ内目標部分へ移動し、ハンバーガーメニューが消えるようにしたいです。
当方java scriptの知識は皆無でテンプレートのデータをそのまま使用しています。

発生している問題・エラーメッセージ

ハンバーガーメニューをクリックするとメニューが現れ、メニューをクリックすると同一ページ内のその部分に飛ぶ。リンクにはちゃんと飛ぶのですが、表示されたハンバーガーメニューが画面から消えず、表示されたままになります。 その後ろで指定した同一ページ内目標部分が表示されています。 なぜか「ホーム」リンク先URLは「index.html」はちゃんと飛び、素直に消えます。

該当のソースコード

【html】 <ul class="list-unstyled s-header__nav-menu"> <li class="s-header__nav-menu-item"><a class="s-header__nav-menu-link s-header__nav-menu-link-divider -is-active" href="index.html">HOME</a></li> <li class="s-header__nav-menu-item"><a class="s-header__nav-menu-link s-header__nav-menu-link-divider -is-active" href="index.html#features">商品につきまして</a></li> <li class="s-header__nav-menu-item"><a class="s-header__nav-menu-link s-header__nav-menu-link-divider -is-active" href="#nayami">お洗濯のお悩み</a></li> <li class="s-header__nav-menu-item"><a class="s-header__nav-menu-link s-header__nav-menu-link-divider" href="index.html#faq">よくあるご質問</a></li> </ul> 【js】 var Global=function(){"use strict";var t=function(){$(".carousel").carousel({interval:5e3,pause:"hover"}),$(".tooltips").tooltip(),$(".tooltips-show").tooltip("show"),$(".tooltips-hide").tooltip("hide"),$(".tooltips-toggle").tooltip("toggle"),$(".tooltips-destroy").tooltip("destroy"),$(".popovers").popover(),$(".popovers-show").popover("show"),$(".popovers-hide").popover("hide"),$(".popovers-toggle").popover("toggle"),$(".popovers-destroy").popover("destroy")},e=function(){$(function(){$("a[href*=#js__scroll-to-]:not([href=#js__scroll-to-])").on("click",function(){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var t=$(this.hash);if(t=t.length?t:$("[name="+this.hash.slice(1)+"]"),t.length)return $("html,body").animate({scrollTop:t.offset().top-90},1e3),!1}})})},o=function(){$(".js__fullwidth-img").each(function(){$(this).css("background-image","url("+$(this).children("img").attr("src")+")"),$(this).children("img").hide()})},i=function(){var t=$(".js__bg-overlay"),e=$(".js__header-overlay"),o=$(".js__trigger");o.on("click",function(){t.toggleClass("-is-open"),e.toggleClass("-is-open"),o.toggleClass("-is-active")})},s=function(){$(".js__ver-center-aligned").each(function(){$(this).css("padding-top",$(this).parent().height()/2-$(this).height()/2)}),$(window).resize(function(){$(".js__ver-center-aligned").each(function(){$(this).css("padding-top",$(this).parent().height()/2-$(this).height()/2)})})},h=function(){$("[data-auto-height]").each(function(){var t=$(this),e=$("[data-height]",t),o=0,i=t.attr("data-mode"),s=parseInt(t.attr("data-offset")?t.attr("data-offset"):0);e.each(function(){"height"==$(this).attr("data-height")?$(this).css("height",""):$(this).css("min-height","");var t="base-height"==i?$(this).outerHeight():$(this).outerHeight(!0);t>o&&(o=t)}),o+=s,e.each(function(){"height"==$(this).attr("data-height")?$(this).css("height",o):$(this).css("min-height",o)}),t.attr("data-related")&&$(t.attr("data-related")).css("height",t.height())})};return{init:function(){t(),e(),o(),i(),s(),h()}}}();$(document).ready(function(){Global.init()});

こちらのサイトで他にも似たお悩みの方のコメントも拝見致しましたが
jsのどの部分を修正、追記などすれば良いのかもわかりません。
初心者ですがどうかよろしくお願い致します。

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

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

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

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

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

task58.js

2022/09/23 08:39

javascriptがminify(圧縮)されてるので解読困難です。 できれば素のコードが欲しいですが...
yoshi73

2022/09/23 11:02

ご返信ありがとうございます。 貼り付けさせていただきます。 どうぞよろしくお願い致します。 var Global=function(){"use strict";var t=function(){$(".carousel").carousel({interval:5e3,pause:"hover"}),$(".tooltips").tooltip(),$(".tooltips-show").tooltip("show"),$(".tooltips-hide").tooltip("hide"),$(".tooltips-toggle").tooltip("toggle"),$(".tooltips-destroy").tooltip("destroy"),$(".popovers").popover(),$(".popovers-show").popover("show"),$(".popovers-hide").popover("hide"),$(".popovers-toggle").popover("toggle"),$(".popovers-destroy").popover("destroy")},e=function(){$(function(){$("a[href*=#js__scroll-to-]:not([href=#js__scroll-to-])").on("click",function(){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var t=$(this.hash);if(t=t.length?t:$("[name="+this.hash.slice(1)+"]"),t.length)return $("html,body").animate({scrollTop:t.offset().top-90},1e3),!1}})})},o=function(){$(".js__fullwidth-img").each(function(){$(this).css("background-image","url("+$(this).children("img").attr("src")+")"),$(this).children("img").hide()})},i=function(){var t=$(".js__bg-overlay"),e=$(".js__header-overlay"),o=$(".js__trigger");o.on("click",function(){t.toggleClass("-is-open"),e.toggleClass("-is-open"),o.toggleClass("-is-active")})},s=function(){$(".js__ver-center-aligned").each(function(){$(this).css("padding-top",$(this).parent().height()/2-$(this).height()/2)}),$(window).resize(function(){$(".js__ver-center-aligned").each(function(){$(this).css("padding-top",$(this).parent().height()/2-$(this).height()/2)})})},h=function(){$("[data-auto-height]").each(function(){var t=$(this),e=$("[data-height]",t),o=0,i=t.attr("data-mode"),s=parseInt(t.attr("data-offset")?t.attr("data-offset"):0);e.each(function(){"height"==$(this).attr("data-height")?$(this).css("height",""):$(this).css("min-height","");var t="base-height"==i?$(this).outerHeight():$(this).outerHeight(!0);t>o&&(o=t)}),o+=s,e.each(function(){"height"==$(this).attr("data-height")?$(this).css("height",o):$(this).css("min-height",o)}),t.attr("data-related")&&$(t.attr("data-related")).css("height",t.height())})};return{init:function(){t(),e(),o(),i(),s(),h()}}}();$(document).ready(function(){Global.init()});
yoshi73

2022/09/24 00:14

申し訳ありません。上記の物ではなく下記の方かもしれません。 貼り付けさせていただきます。 // Global Javascript Initialization var Global = function() { 'use strict'; // Bootstra Components var handleBootstrapComponents = function() { // Bootstrap Carousel $('.carousel').carousel({ interval: 5000, pause: 'hover' }); // Tooltips $('.tooltips').tooltip(); $('.tooltips-show').tooltip('show'); $('.tooltips-hide').tooltip('hide'); $('.tooltips-toggle').tooltip('toggle'); $('.tooltips-destroy').tooltip('destroy'); // Popovers $('.popovers').popover(); $('.popovers-show').popover('show'); $('.popovers-hide').popover('hide'); $('.popovers-toggle').popover('toggle'); $('.popovers-destroy').popover('destroy'); } // Scroll To Section var handleScrollToSection = function() { $(function() { $('a[href*=#js__scroll-to-]:not([href=#js__scroll-to-])').on('click', function() { if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top - 90 }, 1000); return false; } } }); }); } // Handle Promo Section var handlePromoSection = function() { $('.js__fullwidth-img').each(function() { $(this).css('background-image', 'url(' + $(this).children('img').attr('src') + ')'); $(this).children('img').hide(); }); } // Handle Overlay var handleOverlay = function() { var overlay = $('.js__bg-overlay'), headerOverlay = $('.js__header-overlay'), trigger = $('.js__trigger'); trigger.on('click', function() { overlay.toggleClass('-is-open'); headerOverlay.toggleClass('-is-open'); trigger.toggleClass('-is-active'); }); } // Vertical Center Aligned // Note! This works only with promo block and background image via CSS. var handleVerticalCenterAligned = function() { $('.js__ver-center-aligned').each(function() { $(this).css('padding-top', $(this).parent().height() / 2 - $(this).height() / 2); }); $(window).resize(function() { $('.js__ver-center-aligned').each(function() { $(this).css('padding-top', $(this).parent().height() / 2 - $(this).height() / 2); }); }); } // handle group element heights var handleEqualHeight = function() { $('[data-auto-height]').each(function() { var parent = $(this); var items = $('[data-height]', parent); var height = 0; var mode = parent.attr('data-mode'); var offset = parseInt(parent.attr('data-offset') ? parent.attr('data-offset') : 0); items.each(function() { if ($(this).attr('data-height') == "height") { $(this).css('height', ''); } else { $(this).css('min-height', ''); } var height_ = (mode == 'base-height' ? $(this).outerHeight() : $(this).outerHeight(true)); if (height_ > height) { height = height_; } }); height = height + offset; items.each(function() { if ($(this).attr('data-height') == "height") { $(this).css('height', height); } else { $(this).css('min-height', height); } }); if(parent.attr('data-related')) { $(parent.attr('data-related')).css('height', parent.height()); } }); } return { init: function() { handleBootstrapComponents(); // initial setup for Bootstrap Components handleScrollToSection(); // initial setup for Scroll To Section handlePromoSection(); // initial setup for Promo Section handleOverlay(); // initial setup for Overlay handleVerticalCenterAligned(); // initial setup for Vertical Center Aligned handleEqualHeight(); // initial setup for Equal Height } } }(); $(document).ready(function() { Global.init(); });
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問