I want to use smooth scroll to go to the anchors on my homepage. I use this jQuery code:
$(document).ready(function(){
$('a').click(function(){
$('html, body').animate({
scrollTop: $($.attr(this, 'href')).offset().top
}, 1000);
return false;
});
});
And this is the HTML code:
<div id="menu">
<div id="menu-contain">
<ul>
<li><a class="home" href="#">Home</a></li>
<li><a class="about" href="#about">About</a></li>
<li><a class="projects" href="#projects">Projects</a></li>
<li><a class="contact" href="#contact">Contact</a></li>
</ul>
</div>
</div>
This works quite fine for every anchor but the first. If I have a look at the console there is an error if I click on the first link:
Cannot read property 'top' of undefined
I found a lot of threads to this error but I didn't find a solution which works for me.
Suggestions appreciated :)