Answer the question
In order to leave comments, you need to log in
How to smoothly scroll to an anchor that is on another page?
Hello.
The question is - how can you scroll smoothly to an anchor that is on another page?
Example
That is, I need the page to load and then a smooth scroll begins.
<a href="about.html#about">About</a>
$('a[href^="#"]').click(function(){
var el = $(this).attr('href');
$('body').animate({
scrollTop:$(el).offset().top}, 2000);
return false;
});
Answer the question
In order to leave comments, you need to log in
this scheme does not work.
$(function(){
if(location.hash){ //Будет #about, к примеру
$('html, body').animate({
scrollTop : $(location.hash).offset().top
}, 2000);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question