scrolltrack.js 812 B

12345678910111213141516171819202122232425
  1. function scrolltrack() {
  2. var i=anchors.length-1;
  3. var ruler=(window.innerHeight || document.documentElement.clientHeight) / 8;
  4. if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight - 20) {
  5. document.getElementById(anchors[i]+'L').style.color='#97C3E9';
  6. } else {
  7. while (i>=0) {
  8. if (document.getElementById(anchors[i]).getBoundingClientRect().top<=ruler) {
  9. document.getElementById(anchors[i]+'L').style.color='#97C3E9';
  10. break;
  11. } else {
  12. document.getElementById(anchors[i]+'L').style.color='#3088D4';
  13. }
  14. i--;
  15. }
  16. }
  17. if (i>=0) {
  18. // console.log('Arrivati a: '+anchors[i]);
  19. document.getElementById(anchors[i]+'L').scrollIntoView({behavior: "smooth", block: "center"});
  20. }
  21. while (i>0) {
  22. i--;
  23. document.getElementById(anchors[i]+'L').style.color='#3088D4';
  24. }
  25. }