Skip to content

Commit b2e6372

Browse files
committed
Update homepage.js
1 parent c333515 commit b2e6372

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

homepage/homepage.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,35 @@ checkPWA();*/
174174

175175
// add scroll event listeners
176176

177-
const screenHeight = window.innerHeight;
177+
const screenHeight = window.innerHeight,
178+
featurePoints = document.querySelectorAll('#features .ftPoint'),
179+
180+
pointMargin = 34,
181+
startPointAnimation = (screenHeight / 3) + pointMargin,
182+
183+
184+
let totalPointAnimation = startPointAnimation,
185+
pointStaggerIntervals = [];
178186

179-
const featurePoints = document.querySelectorAll('#features .ftPoint');
187+
// set stagger intervals for feature points
188+
featurePoints.forEach(point => {
180189

181-
const startPointAnimation = screenHeight / 3;
182-
const pointStaggerInterval = 34 + (7 * 5);
190+
totalPointAnimation += point.clientHeight + 34;
183191

184-
function checkScrollAnimations() {
192+
pointStaggerIntervals.push(totalPointAnimation);
193+
194+
});
195+
196+
197+
function checkPointAnimations() {
185198

186199
// window scroll position
187200
const scrolled = window.scrollY || window.pageYOffset;
188-
189-
// add staggered feature points animation
201+
202+
// check feature point animation
190203
featurePoints.forEach((point, index) => {
191-
192-
const pointAnimation = startPointAnimation + (pointStaggerInterval * index);
204+
205+
const pointAnimation = pointStaggerIntervals[index];
193206

194207
if (scrolled >= pointAnimation) {
195208
point.classList.add('visible');
@@ -202,5 +215,5 @@ function checkScrollAnimations() {
202215
}
203216

204217

205-
window.addEventListener('scroll', checkScrollAnimations);
218+
window.addEventListener('scroll', checkPointAnimations);
206219
checkScrollAnimations();

0 commit comments

Comments
 (0)