2016-12-03 2 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^="#"]') 
관련 문제