Skip to content

Commit 8cf122f

Browse files
committed
Update some values if browser resized
1 parent 09f4034 commit 8cf122f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

js/main.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,18 @@ 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 headerYOffset = (window.innerHeight)/10 - parseFloat(getComputedStyle(_("h2")).fontSize) - 5
106+
107+
let headerYOffset = (window.innerHeight)/10 - parseFloat(getComputedStyle(_("h2")).fontSize) - 5
107108

108109
// Current scroll position
109110
let scrollPos = 0
110111

112+
// fire when window resized, e.g. when device is turned
113+
window.addEventListener('resize', function(event) {
114+
intro = _('.content').offsetTop; // set top of content
115+
headerYOffset = (window.innerHeight)/10 - parseFloat(getComputedStyle(_("h2")).fontSize) - 5
116+
}, true);
117+
111118
document.addEventListener('scroll', () => {
112119
// Update scroll position on scroll
113120
scrollPos = window.scrollY
@@ -131,10 +138,6 @@ ready(() => {
131138
// run every 150ms, put most things-that-change-with-scrolling here.
132139
// more efficient than putting them in the scroll event
133140
window.setInterval(function(){
134-
intro = _('.content').offsetTop; // set top of content
135-
// ^ this is in a loop so that if the screen is turned it
136-
// will update with new values
137-
138141
// if user scrolls below hero, show scroll up button
139142
if (scrollPos > intro) {
140143
scrollup.classList.add("show")

0 commit comments

Comments
 (0)