私は BackboneJS と Bootstrap を使用しています。訪問者がボタンをクリックした後、一部のコンテンツでスクロール スパイを有効にしようとしていました。
したがって、ユーザーがそのボタンをクリックすると、これらが実行されます。
$('#frontPageNav').css('display', 'block'); // It was hidden on load
$('#frontPageNav').scrollspy(); // Activate scrollspy, this is where the error happens
$('[data-spy="scroll"]').each(function () {
var $spy = $(this).scrollspy('refresh'); // I think this is not needed because nothing was invisible before
});
$('#frontPageNav li').on('activate', function () { // This never gets emitted
alert('activate!');
});
そして、スパイされたいコンテンツは次のように配置されます。
<div data-spy="scroll" data-target="#frontPageNav">
<div id="home-top" class="row slide">
</div>
<div id="home-how" class="row slide">
</div>
<div id="home-join" class="row slide">
</div>
</div>
ページの他の要素には data-spy 属性がないため、これがスパイされた唯一のコンテンツであると思われますが、明らかにそうではありません: ページの読み込み時にエラーが発生Uncaught TypeError: Cannot read property 'top' of null
します$.position()
。存在しない要素。Chrome の開発者ツールで例外ブレーキをオンにしました。キャッチされなかった例外は、bootstrap.js の 454 行目にあり、&& [[$href.position().top, href]]) || null
ホバーhref
すると、セレクターはマークアップにない要素用ですが、それを含むハッシュへのリンク。
これは、scrollspy プラグインが、すべてのリンクをスパイしhref="#something"
、その ID を持つマークアップ要素を見つけることになっていると考えていることを意味しますか? で要素にスパイ アクションを維持しないのはなぜdata-spy="scroll"
ですか。