1
ページ全体の視差画像の下にある下矢印からページの別のセクションにリンクするドロップアンカーがあります。それは行くドロップアンカーをスキップ/ジャンプする
<section id="first" class="big-image parallax lander" style="background-image: url("https://wagstaffsandbx.wpengine.com/wp-content/uploads/2017/06/Homepage-Photo-1.jpg"); background-position: 50% -7.2px;" data-stellar-background-ratio="0.2" data-stellar-vertical-offset="50">
<a href="#welcome" class="arrow"><img class="down-arrow" src="https://wagstaffsandbx.wpengine.com/wp-content/uploads/2017/06/down-arrow.png" alt="down-arrow"></a>
</section>
:ドロップアンカー
<section id="welcome" class="text-block"><h1>welcome</h1><p>Pitchfork mumblecore stumptown, intelligentsia wolf put a bird on it man bun wayfarers organic actually sartorial. Sriracha disrupt kickstarter fingerstache selvage pour-over. Paleo ugh lumbersexual, kinfolk banjo banh mi meditation cliche 3 wolf moon single-origin coffee viral blog polaroid pop-up.</p>
</section>
クリックすると、矢印の作品ではなく、ドロップアンカーへのスムーズなスクロールは、それが適切な場所にスクロールして、何のために下方向にシフトしていない、起こり明らかな理由。
スムーズなスクロールを実装するために使用しているjQueryは次のとおりです。パスワード
を:サイトを参照してデモ PW:サイトを参照してください https://wagstaffsandbx.wpengine.com/test-stellar/UN:あなたがここにアクションで問題を見ることができます
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a.arrow").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top -140
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
</script>
:あなたは140pxのナビゲーションのためにそこにオフセットだわかります
アイデア?
これは動作します。ありがとうございました!私はまだJavascriptを学んでいます。あなたが提供したコードスニペットが何をしているのか説明できますか?なぜそれが動作するのか理解したいです。 – ludditedev
こちらの記事をご覧ください:https://css-tricks.com/using-the-html5-history-api/ –