Skip to content

Commit f792859

Browse files
committed
Debounce scroll and resize through rAF
1 parent 2eb9415 commit f792859

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

js/theme.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ function ThemeNav () {
2929
// Set scroll monitor
3030
self.win.on('scroll', function () {
3131
if (!self.linkScroll) {
32-
self.winScroll = true;
32+
if (!self.winScroll) {
33+
self.winScroll = true;
34+
requestAnimationFrame(self.onScroll.bind(self));
35+
}
3336
}
3437
});
35-
setInterval(function () { if (self.winScroll) self.onScroll(); }, 25);
3638

3739
// Set resize monitor
3840
self.win.on('resize', function () {
39-
self.winResize = true;
41+
if (!self.winResize) {
42+
self.winResize = true;
43+
requestAnimationFrame(self.onResize.bind(self));
44+
}
4045
});
41-
setInterval(function () { if (self.winResize) self.onResize(); }, 25);
46+
4247
self.onResize();
4348
});
4449
};

0 commit comments

Comments
 (0)