diff --git a/static/script.js b/static/script.js index 2c555f6..81b3e64 100644 --- a/static/script.js +++ b/static/script.js @@ -39,7 +39,6 @@ function updateTrack(newTrackName) { UPDATE_INTERVAL = setInterval(() => { if (added < TrackNameLen) { trackName.innerHTML += newTrackName[added]; - console.log(added, TrackNameLen, newTrackName[added]); added += 1; } @@ -103,22 +102,36 @@ function getScrollPosition() { return Math.floor(scrolled); } +function getBlockScrollPosition(block_id) { + const blockHeight = document.getElementById(block_id).clientHeight; + const fullPageHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight; + const restPageHeight = fullPageHeight - blockHeight; + const windowScroll = document.documentElement.scrollTop - restPageHeight; + const scrolled = (windowScroll / fullPageHeight) * 100; + if (0 < Math.floor(scrolled) ) { + return 0 + } else { + return Math.floor(scrolled) * -1; + } +} + const header = document.getElementById("header"); let last_Y_pos = 0; let header_opacity = 0; +const HEADER_ACTIVATION_PERCENT = 30; +const HEADER_DEACTIVATION_PERCENT = 20; window.onscroll = () => { - let scrollPosition = getScrollPosition(); - - if (scrollPosition < 1) { + let scrollPosition = getBlockScrollPosition('section_landing'); + if (scrollPosition > HEADER_ACTIVATION_PERCENT) { header.style.display = "none"; } else { header.style.display = "block"; } - if (window.scrollY > last_Y_pos && scrollPosition > 1) { + if (window.scrollY > last_Y_pos && scrollPosition < HEADER_ACTIVATION_PERCENT) { header_opacity += 0.1; - } else if (window.scrollY < last_Y_pos && scrollPosition < 1) + } else if (window.scrollY < last_Y_pos && scrollPosition > HEADER_DEACTIVATION_PERCENT) header_opacity -= 0.1; last_Y_pos = window.scrollY;