2016-12-03 5 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*=#] 

Try использование:

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