Skip to content

Commit 9e55b03

Browse files
author
Daniel Ma
committed
🐎 only calculate .scrollTop() once in scroll callback
1 parent 6f9b3b3 commit 9e55b03

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

parallax.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,12 @@
272272
Parallax.requestRender();
273273
})
274274
.on('scroll.px.parallax load.px.parallax', function() {
275+
var winScrollTop = $win.scrollTop();
275276
var scrollTopMax = Parallax.docHeight - Parallax.winHeight;
276277
var scrollLeftMax = Parallax.docWidth - Parallax.winWidth;
277-
Parallax.scrollTop = Math.max(0, Math.min(scrollTopMax, $win.scrollTop()));
278+
Parallax.scrollTop = Math.max(0, Math.min(scrollTopMax, winScrollTop));
278279
Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $win.scrollLeft()));
279-
Parallax.overScroll = Math.max($win.scrollTop() - scrollTopMax, Math.min($win.scrollTop(), 0));
280+
Parallax.overScroll = Math.max(winScrollTop - scrollTopMax, Math.min(winScrollTop, 0));
280281
Parallax.requestRender();
281282
});
282283

parallax.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)