Browse Source

adding bugfixes

master
Björn 5 years ago
parent
commit
e649c4769a
2 changed files with 8 additions and 15 deletions
  1. +1
    -1
      dist/js/demo-386.js
  2. +7
    -14
      src/TinyOnePage.riot

+ 1
- 1
dist/js/demo-386.js
File diff suppressed because it is too large
View File


+ 7
- 14
src/TinyOnePage.riot View File

@ -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 + "']"));
}
}


Loading…
Cancel
Save