Skip to content

Commit

Permalink
Minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrme committed Jul 8, 2024
1 parent a9735c0 commit 09f4034
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ready(() => {
// i.e. if there are three circles, this is 50% as the bar's width
// must increase by 50% to get from the first to second circle, etc
const increment = 100/(circles.length-1)
const headerYTrans = (window.innerHeight)/10 - parseFloat(getComputedStyle(_("h2")).fontSize) - 5
const headerYOffset = (window.innerHeight)/10 - parseFloat(getComputedStyle(_("h2")).fontSize) - 5

// Current scroll position
let scrollPos = 0
Expand All @@ -116,10 +116,14 @@ ready(() => {
sections.forEach((section, i) => {
const rect = section.getBoundingClientRect()

// look for header that has already been activated with class sticky
header = section.querySelector("h2.stickyheader.sticky")
if (header) {
header.style.transform = `scale(10) translate(${(rect.top) / (rect.bottom - rect.top)*70}%, ${headerYTrans}px)`
// only bother doing these transformations if the section is actually on screen
// i.e. the section bottom is lower than the top of the screen
if (rect.bottom > 0) {
// look for header that has already been activated with class sticky
header = section.querySelector("h2.stickyheader.sticky")
if (header) {
header.style.transform = `scale(10) translate(${(rect.top) / (rect.bottom - rect.top)*70}%, ${headerYOffset}px)`
}
}
})
})
Expand Down

0 comments on commit 09f4034

Please sign in to comment.