Button which scroll to div (2nd project)

Button which scroll to div (2nd project)
0

#1

Hi i stuck in a 2nd project. I need to create navi buttons which follows to diffrent divs.
I’m confused because in a previous lessons there were no informations about that or i missed something.
I’m trying to do that with js but i do not understand all of informations or code parts which i found in the internet.
It’s my pen: https://codepen.io/3dx2/pen/NXRgoE
Now its working but navi bar cover choosen divs when already scrolled to them.
I also don’t understand this part of code :
$(“html,body”).animate({
scrollTop: $("#target4").offset().top

I dont need any effects like slow etc. just want to navigate between diffrent parts of page.
I think js part in a course was to poor compare to project requirements but it only my opinion.
Thank you!


#2

All you have to do to set up an internal navigation is write a link that points to a portion of your page.

You need your navigation button to be link that refers to a valid id on your page:

<!-- your navigation -->
<a href="#portfolio" class="navigation-link">Porfolio</a>

<!-- and then the portion of the page where you want to navigate -->
<div id="portfolio">
Portfolio
</div>

From MDN documentation:

The HTML <a> element (or anchor element) creates a hyperlink to other web pages, files, locations within the same page, email addresses, or any other URL.


#3

Hey everything work! Thank you very much… But navibar still cover my divs after jump to them. It seems to be like it taking position not from end of navi bar but from top of page. Is it possible to change that?