Skip to content

Commit 09f4034

Browse files
committed
Minor optimization
1 parent a9735c0 commit 09f4034

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

js/main.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ready(() => {
103103
// i.e. if there are three circles, this is 50% as the bar's width
104104
// must increase by 50% to get from the first to second circle, etc
105105
const increment = 100/(circles.length-1)
106-
const headerYTrans = (window.innerHeight)/10 - parseFloat(getComputedStyle(_("h2")).fontSize) - 5
106+
const headerYOffset = (window.innerHeight)/10 - parseFloat(getComputedStyle(_("h2")).fontSize) - 5
107107

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

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

0 commit comments

Comments
 (0)