I will be scrolled to!
40 |I will be scrolled to!
44 |I will be scrolled to!
48 |I will not be scrolled to!
52 |NavSync is an easy to use jQuery plugin that does the heavylifting for syncing your navigation to your content. All it requires is a semantically built navigation menu and a couple of lines of code, easy as pie.
45 |Don't believe me? The tiny code snippet below is all you need to get started with NavSync!
46 | Javascript 47 |$(window).load(function() {
48 | $("nav").navSync();
49 | });
50 | The HTML markup required is also extremely simple, see below for an example. Note that NavSync also supports external links, and will only trigger on elements with a valid anchor on the page. Link number 4 will load without problems.
53 | HTML 54 |<nav>
55 | <a href="#anchor-1">First Link</a>
56 | <a href="#anchor-2">Second Link</a>
57 | <a href="#anchor-3">Third Link</a>
58 | <a href="/example/">Fourth Link</a>
59 | </nav>
60 | NavSync has a number of parameters to make use of, for example the ability to tweak with scrolling behaviour, speed of scrolling animations, and the name of the class applied to your header items. These are available to let you customize the behaviour of NavSync to however you see fit.
71 | 72 |$("nav").navSync({hightlightClass : "highlight-menu-item"});
76 | Changes the default class from "navsync-menu-highlight" to "highlight-menu-item". The class is removed once the item has been scrolled past, and reapplied if the user scrolls up.
77 | 78 |$("nav").navSync({animationTime : 800});
82 | Changes the default animation time for scrolling from 300ms to 800ms, generally scroll speeds of above a second are unwarranted. This should serve as a smell embellishment, not a super funky feature of your website.
83 | 84 |$("nav").navSync({ignoreNavHeightScroll: true});
88 | By default NavSync will also take into account the height of the header when scrolling to a given anchor, this option can be disabled independently of the former option and is advised if that is the case.
89 | 90 |To report bugs, problems, or other inconsistencies you can find the GitHub repo for the project below.
100 | 101 |You can contact me via my GitHub page or social media, please do not report bugs through social media.
106 | 107 |