Navigation

Inpage navigation

Data attributes

Please pay attention to the following attributes before going further into implementing the JavaScript behaviors of the component:

  • data-ecl-inpage-navigation-container: on the content container, such as the row that contains both the inpage navigation and the content
  • data-ecl-inpage-navigation: on the <nav> itself
  • data-ecl-inpage-navigation-trigger: on the dropdown button that appears on mobile
  • data-ecl-inpage-navigation-trigger-current: on the <span> within the button ; we use it to inject the title of the currently active section
  • data-ecl-inpage-navigation-list: to be applied on the list of links
  • data-ecl-inpage-navigation-link: to be applied on each link in the inpage navigation

Setup

There are 2 ways to initialise the component.

Automatic

Add data-ecl-auto-init attribute to component's markup

<nav
  class="ecl-inpage-navigation"
  data-ecl-inpage-navigation
  data-ecl-auto-init="InpageNavigation"
>
  ...
</nav>

Use the ECL library's autoInit() (ECL.autoInit()) when your page is ready or other custom event you want to hook onto.

Manual

Get target element, create an instance and invoke init().

Given you have 1 element with an attribute data-ecl-inpage-navigation on the page:

var elt = document.querySelector('[data-ecl-inpage-navigation]');
var inpageNavigation = new ECL.InpageNavigation(elt);
inpageNavigation.init();

API