Import Most Visible library

This commit is contained in:
Lucas Larroche 2021-07-24 12:08:45 +07:00
parent 8cb28b3707
commit 4a2e9714f3
5 changed files with 16 additions and 5 deletions

View file

@ -11,6 +11,7 @@
export const scrollspy = {
// Config
mostVisible: null,
minWidth: '992px',
interval: 75,
targets: {
@ -21,7 +22,10 @@ export const scrollspy = {
// Init
init() {
init(mostVisible) {
if (this.mostVisible == null) {
this.mostVisible = mostVisible;
}
if (window.matchMedia('(min-width: ' + this.minWidth + ')').matches) {
this.setActiveNav();
this.scrollStop();
@ -33,7 +37,7 @@ export const scrollspy = {
setActiveNav() {
// Get active section
let currentSection = mostVisible(this.targets.sections).getAttribute('id');
let currentSection = this.mostVisible(this.targets.sections).getAttribute('id');
// Remove all active states
let links = document.querySelectorAll(this.targets.nav + ' a.' + this.targets.active);