File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ ready(() => {
103
103
// i.e. if there are three circles, this is 50% as the bar's width
104
104
// must increase by 50% to get from the first to second circle, etc
105
105
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
107
107
108
108
// Current scroll position
109
109
let scrollPos = 0
@@ -116,10 +116,14 @@ ready(() => {
116
116
sections . forEach ( ( section , i ) => {
117
117
const rect = section . getBoundingClientRect ( )
118
118
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
+ }
123
127
}
124
128
} )
125
129
} )
You can’t perform that action at this time.
0 commit comments