2016-12-03 3 views
0

私は、テスト用のウェブサイトを作成して、そのページの次のセクションに移動するアンカー要素をクリックします。ユーザーがアンカーでをクリックしたときに私のアニメーションが表示されない理由がわかりません。スクロールアニメーションが機能しません

$(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

あなたがHTMLを提供することはできますか? – osmanraifgunes

答えて

1

この$('a[href^="#"]')に変更$('a[href*=#]')。間違った構文を使用していました

+0

ありがとうございました!!!! –

+0

クール、これを回答としてマークしてください –

1

コンソールログを見てください。あり:

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

てみ使用:

$('a[href^="#"]') 
関連する問題