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

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

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

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

HTML

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

CSS

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

Q&A

解決済

1回答

2205閲覧

使用しているjqueryでリンク範囲をボタン全体にしたい

退会済みユーザー

退会済みユーザー

総合スコア0

jQuery

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

HTML

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

CSS

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

0グッド

0クリップ

投稿2017/02/17 06:46

お世話になります。

レスポンシブなナビを作成中で、下記jquery(stellarnav)を使用しているのですが、
スマホ時、下階層の+アイコン限定ではなく、ボタン全体にリンクを貼りたいのですが、
どこを触ればよいでしょうか?
文字数オーバーしてしまうので、htmlは省略しています(デモでご覧いただければ)

デモはこちら
http://vinnymoreira.com/stellarnav-js-demo/

css

1/* mobile nav */ 2.stellarnav .menu-toggle { color: #777; padding: 15px; } 3.stellarnav.mobile { position: static; } 4.stellarnav.mobile.fixed { position: static; } 5.stellarnav.mobile ul { position: relative; display: none; } 6.stellarnav.mobile.active { padding-bottom: 0; } 7.stellarnav.mobile.active > ul { display: block; } 8.stellarnav.mobile ul { text-align: left; } 9.stellarnav.mobile > ul > li { display: block; } 10.stellarnav.mobile > ul > li > a { padding: 15px; } 11.stellarnav.mobile ul { background: rgba(221, 221, 221, 1); } 12.stellarnav.mobile ul ul { position: relative; opacity: 1; visibility: visible; width: auto; display: none; -moz-transition: none; -webkit-transition: none; -o-transition: color 0 ease-in; transition: none; } 13.stellarnav.mobile ul ul ul { left: auto; top: auto; } 14.stellarnav.mobile li.drop-left ul ul { right: auto; } 15.stellarnav.mobile li a { border-bottom: 1px solid rgba(255, 255, 255, .15); } 16.stellarnav.mobile li.has-sub a { padding-right: 50px; } 17.stellarnav.mobile.light li a { border-bottom: 1px solid rgba(0, 0, 0, .15); } 18.stellarnav.mobile li a.dd-toggle { border: 0; } 19.stellarnav.mobile.light li a.dd-toggle { border: 0; } 20.stellarnav.mobile .menu-toggle, .stellarnav.mobile .dd-toggle, .stellarnav.mobile .close-menu { display: block; } 21.stellarnav.mobile li.call-btn-mobile { border-right: 1px solid rgba(255, 255, 255, .1); box-sizing: border-box; } 22.stellarnav.mobile li.call-btn-mobile, .stellarnav.mobile li.call-btn-location { display: inline-block; width: 50%; text-transform: uppercase; text-align: center; } 23.stellarnav.mobile li.call-btn-mobile.full, .stellarnav.mobile li.call-btn-location.full { display: block; width: 100%; text-transform: uppercase; border-right: 0; text-align: left; } 24.stellarnav.mobile li.call-btn-mobile i, .stellarnav.mobile li.call-btn-location i { margin-right: 5px; } 25.stellarnav.mobile.light ul { background: rgba(255, 255, 255, 1); } 26.stellarnav.mobile.dark ul { background: rgba(0, 0, 0, 1); } 27.stellarnav.mobile.dark ul ul { background: rgba(255, 255, 255, .08); } 28.stellarnav.mobile.light li.call-btn-mobile { border-right: 1px solid rgba(0, 0, 0, .1); } 29.stellarnav.mobile.top { position: absolute; width: 100%; top: 0; left: 0; z-index: 9999; } 30.stellarnav.mobile li.has-sub > a:after, .stellarnav.mobile li li.has-sub > a:after, .stellarnav.mobile li.drop-left li.has-sub > a:after { display: none; } 31/* mobile nav */

javascript

1(function($) { 2 $.fn.stellarNav = function(options, width, breakpoint) { 3 4 var $nav, $width, $breakpoint; 5 nav = $(this); 6 width = $(window).width(); 7 8 // default settings 9 var settings = $.extend( { 10 theme : 'plain', // adds default color to nav. (light, dark) 11 breakpoint: 768, // number in pixels to determine when the nav should turn mobile friendly 12 phoneBtn: false, // adds a click-to-call phone link to the top of menu - i.e.: "18009084500" 13 locationBtn: false, // adds a location link to the top of menu - i.e.: "/location/", "http://site.com/contact-us/" 14 sticky : false, // makes nav sticky on scroll (desktop only) 15 position: 'static', // 'static' or 'top' - when set to 'top', this forces the mobile nav to be placed absolutely on the very top of page 16 showArrows: true, // shows dropdown arrows next to the items that have sub menus 17 closeBtn : false, // adds a close button to the end of nav 18 scrollbarFix: false // fixes horizontal scrollbar issue on very long navs 19 }, options ); 20 21 return this.each( function() { 22 23 // defines black or white themes 24 if (settings.theme == 'light' || settings.theme == 'dark') { 25 nav.addClass(settings.theme); 26 } 27 28 if (settings.breakpoint) { 29 breakpoint = settings.breakpoint; 30 } 31 32 // adds a location page link to the beginning of nav 33 if (settings.locationBtn) { 34 35 if(!settings.phoneBtn) { 36 var cssClass = 'full'; 37 } else { 38 var cssClass = ''; 39 } 40 41 var btn = '<li class="call-btn-location ' + cssClass + '"><a href="'+ settings.locationBtn +'"><i class="fa fa-map-marker"></i> Location</a></li>'; 42 nav.find('ul:first').prepend(btn); 43 44 } 45 46 // adds a click-to-call link to the beginning of nav 47 if (settings.phoneBtn) { 48 49 if(!settings.locationBtn) { 50 var cssClass = 'full'; 51 } else { 52 var cssClass = ''; 53 } 54 55 var btn = '<li class="call-btn-mobile ' + cssClass + '"><a href="tel:'+ settings.phoneBtn +'"><i class="fa fa-phone"></i> Call us</a></li>'; 56 nav.find('ul:first').prepend(btn); 57 58 } 59 60 // Makes nav sticky on scroll 61 if (settings.sticky) { 62 navPos = nav.offset().top; 63 if(width >= breakpoint) { 64 $(window).bind('scroll', function() { 65 if ($(window).scrollTop() > navPos) { 66 nav.addClass('fixed'); 67 } 68 else { 69 nav.removeClass('fixed'); 70 } 71 }); 72 } 73 } 74 75 if (settings.position == 'top') { 76 nav.addClass('top'); 77 } 78 79 if (!settings.showArrows) { 80 nav.addClass('hide-arrows'); 81 } 82 83 if (settings.closeBtn) { 84 // adds a link to end of nav to close it 85 nav.find('ul:first').append('<li><a href="#" class="close-menu"><i class="fa fa-close"></i> Close Menu</a></li>'); 86 } 87 88 if (settings.scrollbarFix) { 89 $('body').addClass('stellarnav-noscroll-x'); 90 } 91 92 // adds the toggle button to open and close nav 93 nav.prepend('<a href="#" class="menu-toggle"><i class="fa fa-bars"></i> Menu</a>'); 94 95 // opens and closes menu 96 $('.menu-toggle').on('click', function(e) { 97 e.preventDefault(); 98 nav.find('ul:first').stop(true, true).slideToggle(250); 99 nav.toggleClass('active'); 100 }); 101 102 // actives the close button 103 $('.close-menu').click(function() { 104 nav.find('ul:first').stop(true, true).slideUp(250).toggleClass('active'); 105 nav.removeClass('active'); 106 }); 107 108 109 // adds toggle button to li items that have children 110 nav.find('li a').each(function() { 111 if ($(this).next().length > 0) { 112 $(this).parent('li').addClass('has-sub').append('<a class="dd-toggle" href="#"><i class="fa fa-plus"></i></a>'); 113 } 114 }); 115 116 // expands the dropdown menu on each click 117 nav.find('li .dd-toggle').on('click', function(e) { 118 e.preventDefault(); 119 //$(this).parent('li').toggleClass('hover'); 120 $(this).parent('li').children('ul').stop(true, true).slideToggle(250); 121 $(this).parent('li').toggleClass('open'); 122 }); 123 124 var resetTriggers = function() { 125 nav.find('li').unbind('mouseenter'); 126 nav.find('li').unbind('mouseleave'); 127 } 128 129 var setTriggers = function() { 130 nav.find('li').on('mouseenter', function(){ 131 $(this).addClass('hover'); 132 $(this).children('ul').stop(true, true).slideDown(250); 133 }); 134 nav.find('li').on('mouseleave', function(){ 135 $(this).removeClass('hover'); 136 $(this).children('ul').stop(true, true).slideUp(250); 137 }); 138 } 139 windowCheck(); 140 141 // check browser width in real-time 142 function windowCheck() { 143 var browserWidth = window.outerWidth; 144 145 if(browserWidth <= breakpoint) { 146 // mobile/tablet nav 147 148 resetTriggers(); 149 nav.addClass('mobile'); 150 nav.removeClass('desktop'); 151 152 // closes the menu when resizing window back to desktop 153 if( !nav.hasClass('active') && nav.find('ul:first').is(':visible') ) { 154 //nav.addClass('active'); 155 nav.find('ul:first').hide(); 156 } 157 158 } else { 159 // desktop nav 160 nav.addClass('desktop'); 161 nav.removeClass('mobile'); 162 163 if(nav.hasClass('active')) { 164 nav.removeClass('active'); 165 } 166 167 // ensures stellarnav is visible after resizing window 168 if( !nav.hasClass('active') && nav.find('ul:first').is(':hidden') ) { 169 nav.find('ul:first').show(); 170 } 171 172 // hides items that were open on mobile 173 $('li.open').removeClass('open').find('ul:visible').hide(); 174 175 resetTriggers(); 176 setTriggers(); 177 } 178 } 179 180 $(window).on('resize', function() { 181 windowCheck(); 182 }); 183 }); 184 } 185}(jQuery)); 186

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

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

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

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

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

guest

回答1

0

ベストアンサー

下の階層があるときには「+」ボタンが自動付加されるので、その仕組みを使って動作を付け加えるといいと思います。

javascript

1 2jQuery('.stellarnav').stellarNav({ // stellarNav を設定 3 theme: 'dark' 4}) 5.find(".dd-toggle").siblings("a").on("click", function(){ // 下の階層があるリンクをクリックした時の動作 6 $(this).siblings(".dd-toggle").click(); // 「+」アイコンをクリックする 7 return false; 8}); 9

投稿2017/02/17 08:24

kura

総合スコア368

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

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

退会済みユーザー

退会済みユーザー

2017/02/20 00:25

大変助かりました!ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問