Ich versuche, meine Seite zu einem bestimmten <section>
auf Klick auf eine href zu scrollen. Ich war in der Lage, die Seite zu springen, um die <section>
Ich will es, aber es ist nicht glatt (es ist wie mein .animate funktioniert nicht in der jQuery).jQuery Bildlauf ist nicht animieren
HTML
<li><a href="#about" class="about-link">about us</a></li>
<section class="about" id="about">
<div class="container">
<h1>about us</h1>
<p>text</p>
</div>
</section>
jQuery
$(document).ready(function(){
// Add smooth scrolling to all links
$(".about-link").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
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
Vielen Dank im Voraus!
Ich habe Ihre jQuery und es bewegt mich zu der '' mit der ID, aber es ist immer noch nicht und animierte Bewegung, nur ein sofortiger Sprung. Außerdem versuche ich es mit einem href anstelle einer Schaltfläche zu tun. –
so scrollt das reibungslos, also warum Ihr eins. hast du die "position" mit "top" value richtig angegeben. –
Ich glaube, dass es den richtigen oberen Wert hat, weil es dorthin springt, wo es hingehört, wenn ich auf den Link klicke, aber es tut es immer noch nicht glatt –