|
|
@ -102,6 +102,9 @@ |
|
|
|
// get elements |
|
|
|
const elements = this.$$('.tiny-one-page__inner a'); |
|
|
|
|
|
|
|
// @TODO check offset |
|
|
|
const offset = 25; |
|
|
|
|
|
|
|
// if found |
|
|
|
let hasFound = false; |
|
|
|
|
|
|
@ -124,18 +127,11 @@ |
|
|
|
next = document.querySelector(elements[index + 1].hash); |
|
|
|
} |
|
|
|
|
|
|
|
if (index === 0) { |
|
|
|
offsetTop = 0; |
|
|
|
} |
|
|
|
|
|
|
|
// check if element is visible |
|
|
|
if (!result && ((offsetTop <= window.pageYOffset) && (offsetTop + target.offsetHeight) > window.pageYOffset)) { |
|
|
|
if (!result && |
|
|
|
(target.offsetTop - (window.innerHeight / 2)) <= (window.pageYOffset + offset) && |
|
|
|
(target.offsetTop + target.offsetHeight) - (window.innerHeight / 2) > window.pageYOffset) { |
|
|
|
result = target; |
|
|
|
|
|
|
|
// check if the next element is showing up |
|
|
|
if (next && offsetTop < window.pageYOffset && next.offsetTop > window.pageYOffset && next.offsetTop < (window.pageYOffset + (window.innerHeight / 2))) { |
|
|
|
result = next; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// remove class from each element |
|
|
@ -143,10 +139,7 @@ |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
// @TODO small workaround to ignore gaps between elements where no one found |
|
|
|
if (result) { |
|
|
|
this.addClass(this.$(".tiny-one-page__inner a[href$='" + result.id + "']")); |
|
|
|
} |
|
|
|
this.addClass(this.$(".tiny-one-page__inner a[href$='" + result.id + "']")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|