Section without ID

Turn on debug line for better understanding how script behaves.

Turn off default link option, to disable highlighting menu point when e.g. banner is in view

start

Turn on update hash option to update hash accordingly to current section.

section 1

Change distance from top, into value best suiting your site.

No Id

If section doesn't have id and according nav point, last matched section will keep active status

Section 2
subsection 1

Script also has a functionality to set classes on current sections.

The class set on section can be changed with sectionActiveClass property.

subsection 2

The classes inside navigation also can be changed through the navLinkActiveClass property.

Exact match option

This section doesn't have according menu point.

It is here to make it easier to undestand, how exact matching option works. - It's best place to try it.

If hash updating is enabled, you have the option to either retain the last hash value or set it to false, if no hash updates should occur between sections.

If no section was matched, you can choose another default anchor to gain class "active".
This has to be used together with default link option

section 3

Script has even more options, that weren't included in this small sample

callbacks onInit and onChange

You can select the parent of the anchor tags to become the 'active' class instead of the anchor tags themselves. To achieve this, specify the parent elements to be used as 'active' class holder inside parentsObtainingActiveClass property.

The end

Github

Copy from here:
a[href="#section-3"]