使用しているjqueryでリンク範囲をボタン全体にしたい
解決済
回答 1
投稿
- 評価
- クリップ 0
- VIEW 1,623

退会済みユーザー
お世話になります。
レスポンシブなナビを作成中で、下記jquery(stellarnav)を使用しているのですが、
スマホ時、下階層の+アイコン限定ではなく、ボタン全体にリンクを貼りたいのですが、
どこを触ればよいでしょうか?
文字数オーバーしてしまうので、htmlは省略しています(デモでご覧いただければ)
デモはこちら
http://vinnymoreira.com/stellarnav-js-demo/
/* mobile nav */
.stellarnav .menu-toggle { color: #777; padding: 15px; }
.stellarnav.mobile { position: static; }
.stellarnav.mobile.fixed { position: static; }
.stellarnav.mobile ul { position: relative; display: none; }
.stellarnav.mobile.active { padding-bottom: 0; }
.stellarnav.mobile.active > ul { display: block; }
.stellarnav.mobile ul { text-align: left; }
.stellarnav.mobile > ul > li { display: block; }
.stellarnav.mobile > ul > li > a { padding: 15px; }
.stellarnav.mobile ul { background: rgba(221, 221, 221, 1); }
.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; }
.stellarnav.mobile ul ul ul { left: auto; top: auto; }
.stellarnav.mobile li.drop-left ul ul { right: auto; }
.stellarnav.mobile li a { border-bottom: 1px solid rgba(255, 255, 255, .15); }
.stellarnav.mobile li.has-sub a { padding-right: 50px; }
.stellarnav.mobile.light li a { border-bottom: 1px solid rgba(0, 0, 0, .15); }
.stellarnav.mobile li a.dd-toggle { border: 0; }
.stellarnav.mobile.light li a.dd-toggle { border: 0; }
.stellarnav.mobile .menu-toggle, .stellarnav.mobile .dd-toggle, .stellarnav.mobile .close-menu { display: block; }
.stellarnav.mobile li.call-btn-mobile { border-right: 1px solid rgba(255, 255, 255, .1); box-sizing: border-box; }
.stellarnav.mobile li.call-btn-mobile, .stellarnav.mobile li.call-btn-location { display: inline-block; width: 50%; text-transform: uppercase; text-align: center; }
.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; }
.stellarnav.mobile li.call-btn-mobile i, .stellarnav.mobile li.call-btn-location i { margin-right: 5px; }
.stellarnav.mobile.light ul { background: rgba(255, 255, 255, 1); }
.stellarnav.mobile.dark ul { background: rgba(0, 0, 0, 1); }
.stellarnav.mobile.dark ul ul { background: rgba(255, 255, 255, .08); }
.stellarnav.mobile.light li.call-btn-mobile { border-right: 1px solid rgba(0, 0, 0, .1); }
.stellarnav.mobile.top { position: absolute; width: 100%; top: 0; left: 0; z-index: 9999; }
.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; }
/* mobile nav */
(function($) {
$.fn.stellarNav = function(options, width, breakpoint) {
var $nav, $width, $breakpoint;
nav = $(this);
width = $(window).width();
// default settings
var settings = $.extend( {
theme : 'plain', // adds default color to nav. (light, dark)
breakpoint: 768, // number in pixels to determine when the nav should turn mobile friendly
phoneBtn: false, // adds a click-to-call phone link to the top of menu - i.e.: "18009084500"
locationBtn: false, // adds a location link to the top of menu - i.e.: "/location/", "http://site.com/contact-us/"
sticky : false, // makes nav sticky on scroll (desktop only)
position: 'static', // 'static' or 'top' - when set to 'top', this forces the mobile nav to be placed absolutely on the very top of page
showArrows: true, // shows dropdown arrows next to the items that have sub menus
closeBtn : false, // adds a close button to the end of nav
scrollbarFix: false // fixes horizontal scrollbar issue on very long navs
}, options );
return this.each( function() {
// defines black or white themes
if (settings.theme == 'light' || settings.theme == 'dark') {
nav.addClass(settings.theme);
}
if (settings.breakpoint) {
breakpoint = settings.breakpoint;
}
// adds a location page link to the beginning of nav
if (settings.locationBtn) {
if(!settings.phoneBtn) {
var cssClass = 'full';
} else {
var cssClass = '';
}
var btn = '<li class="call-btn-location ' + cssClass + '"><a href="'+ settings.locationBtn +'"><i class="fa fa-map-marker"></i> Location</a></li>';
nav.find('ul:first').prepend(btn);
}
// adds a click-to-call link to the beginning of nav
if (settings.phoneBtn) {
if(!settings.locationBtn) {
var cssClass = 'full';
} else {
var cssClass = '';
}
var btn = '<li class="call-btn-mobile ' + cssClass + '"><a href="tel:'+ settings.phoneBtn +'"><i class="fa fa-phone"></i> Call us</a></li>';
nav.find('ul:first').prepend(btn);
}
// Makes nav sticky on scroll
if (settings.sticky) {
navPos = nav.offset().top;
if(width >= breakpoint) {
$(window).bind('scroll', function() {
if ($(window).scrollTop() > navPos) {
nav.addClass('fixed');
}
else {
nav.removeClass('fixed');
}
});
}
}
if (settings.position == 'top') {
nav.addClass('top');
}
if (!settings.showArrows) {
nav.addClass('hide-arrows');
}
if (settings.closeBtn) {
// adds a link to end of nav to close it
nav.find('ul:first').append('<li><a href="#" class="close-menu"><i class="fa fa-close"></i> Close Menu</a></li>');
}
if (settings.scrollbarFix) {
$('body').addClass('stellarnav-noscroll-x');
}
// adds the toggle button to open and close nav
nav.prepend('<a href="#" class="menu-toggle"><i class="fa fa-bars"></i> Menu</a>');
// opens and closes menu
$('.menu-toggle').on('click', function(e) {
e.preventDefault();
nav.find('ul:first').stop(true, true).slideToggle(250);
nav.toggleClass('active');
});
// actives the close button
$('.close-menu').click(function() {
nav.find('ul:first').stop(true, true).slideUp(250).toggleClass('active');
nav.removeClass('active');
});
// adds toggle button to li items that have children
nav.find('li a').each(function() {
if ($(this).next().length > 0) {
$(this).parent('li').addClass('has-sub').append('<a class="dd-toggle" href="#"><i class="fa fa-plus"></i></a>');
}
});
// expands the dropdown menu on each click
nav.find('li .dd-toggle').on('click', function(e) {
e.preventDefault();
//$(this).parent('li').toggleClass('hover');
$(this).parent('li').children('ul').stop(true, true).slideToggle(250);
$(this).parent('li').toggleClass('open');
});
var resetTriggers = function() {
nav.find('li').unbind('mouseenter');
nav.find('li').unbind('mouseleave');
}
var setTriggers = function() {
nav.find('li').on('mouseenter', function(){
$(this).addClass('hover');
$(this).children('ul').stop(true, true).slideDown(250);
});
nav.find('li').on('mouseleave', function(){
$(this).removeClass('hover');
$(this).children('ul').stop(true, true).slideUp(250);
});
}
windowCheck();
// check browser width in real-time
function windowCheck() {
var browserWidth = window.outerWidth;
if(browserWidth <= breakpoint) {
// mobile/tablet nav
resetTriggers();
nav.addClass('mobile');
nav.removeClass('desktop');
// closes the menu when resizing window back to desktop
if( !nav.hasClass('active') && nav.find('ul:first').is(':visible') ) {
//nav.addClass('active');
nav.find('ul:first').hide();
}
} else {
// desktop nav
nav.addClass('desktop');
nav.removeClass('mobile');
if(nav.hasClass('active')) {
nav.removeClass('active');
}
// ensures stellarnav is visible after resizing window
if( !nav.hasClass('active') && nav.find('ul:first').is(':hidden') ) {
nav.find('ul:first').show();
}
// hides items that were open on mobile
$('li.open').removeClass('open').find('ul:visible').hide();
resetTriggers();
setTriggers();
}
}
$(window).on('resize', function() {
windowCheck();
});
});
}
}(jQuery));
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
checkベストアンサー
+1
下の階層があるときには「+」ボタンが自動付加されるので、その仕組みを使って動作を付け加えるといいと思います。
jQuery('.stellarnav').stellarNav({ // stellarNav を設定
theme: 'dark'
})
.find(".dd-toggle").siblings("a").on("click", function(){ // 下の階層があるリンクをクリックした時の動作
$(this).siblings(".dd-toggle").click(); // 「+」アイコンをクリックする
return false;
});
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.09%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
2017/02/20 09:25