ゴール内のhref位一致: それは別のものに追加されていない場合に素子から除去されるyes
クラスを防ぎます。jQueryのif文:セクションIDは<a>
私は、次のコードを持っている:
jQuery(function($){
$(window).scroll(function() {
var position = $(this).scrollTop();
if ($('#services').length) {
$('section').each(function() {
var target = $(this).offset().top;
var id = $(this).attr('id');
//if statement goes here i think?
if (position >= target - 79) {
$('.menu-wrap > ul > li > a').removeClass('yes');
$('.menu-wrap > ul > li > a[href*="#' + id + '"]').addClass('yes');
}
});
};
});
})
メニュー項目リンクの1つ(<a href="#~"/>
が)のいずれかのid
と同じである場合、私はposition >= target
をトリガするネストされたif
文を書きたいのですがページのsection
要素。このようにする必要があり
<div class="menu-wrap">
<ul class="nav"><li><a href="#home"/></li><li><a href="second"/></li></ul>
</div>
<section id="home"></section>
<section id="an-id-that-isnt-in-the-menu"></section>
<section id="second"></section>
あなたのhtmlを共有してください。 –
@ ADreNaLiNe-DJ編集 – user1395909
最初に削除するはいクラスはありません。 –