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 contentdata-ecl-inpage-navigation
: on the<nav>
itselfdata-ecl-inpage-navigation-trigger
: on the dropdown button that appears on mobiledata-ecl-inpage-navigation-trigger-current
: on the<span>
within the button ; we use it to inject the title of the currently active sectiondata-ecl-inpage-navigation-list
: to be applied on the list of linksdata-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();