2016-12-03 3 views
0

Ich mache eine Test-Website, wo die Verwendung klickt ein Ankerelement, das sie zum nächsten Abschnitt der Seite führt. Ich kann nicht herausfinden, warum ich meine Animation nicht zeige, wenn der Benutzer auf den Anker klickt.Scroll-Animation funktioniert nicht

$(function() { 
$('a[href*=#]').on('click', function(e) { 
    e.preventDefault(); 
    $('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top}, 2000); 
}); 

});

<head> 
<link href="https://fonts.googleapis.com/css?family=Rokkitt" rel="stylesheet"> 
</head> 
<body> 
    <header> 
    <h1 id="section00" class="siteName selector">Travel More</h1> 
    <h2 class="downPage"><a href="#section01" class="down1">&#x02228;</a></h2> 
    </header> 



    <section id="section01" class="content selector"><a href="#section02" class="down1">Second</a></section> 



    <section id="section02" class="content selector"> 
    <a class="down1" href="#section03">Third</a> 
</section> 


<section id="section03" class="content selector"> 
    <a class="down1" href="#section00">Last</a> 
</section> 




    <footer><p>Travel More 2016</p></footer> 
</body> 

This is a link to the code (codepen)

+0

Sie HTML zur Verfügung stellen kann? – osmanraifgunes

Antwort

1

ändern $('a[href*=#]') dieser $('a[href^="#"]'). Sie verwendeten die falsche Syntax

+0

Das hat funktioniert Danke !!!! –

+0

Cool, bitte markieren Sie dies als Antwort –

1

Schauen Sie sich die Konsolenprotokolle an. Es gibt:

Uncaught Error: Syntax error, unrecognized expression: a[href*=#] 

try:

$('a[href^="#"]') 
Verwandte Themen