Skip to content

Commit

Permalink
registering only a single resize event
Browse files Browse the repository at this point in the history
  • Loading branch information
catdad committed Sep 8, 2023
1 parent 57281ac commit a07e811
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/confetti.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
function confettiCannon(canvas, globalOpts) {
var isLibCanvas = !canvas;
var allowResize = !!prop(globalOpts || {}, 'resize');
var hasResizeEventRegistered = false;
var globalDisableForReducedMotion = prop(globalOpts, 'disableForReducedMotion', Boolean);
var shouldUseWorker = canUseWorker && !!prop(globalOpts || {}, 'useWorker');
var worker = shouldUseWorker ? getWorker() : null;
Expand Down Expand Up @@ -563,6 +564,7 @@
animationObj = null;

if (allowResize) {
hasResizeEventRegistered = false;
global.removeEventListener('resize', onResize);
}

Expand All @@ -573,7 +575,8 @@
}
}

if (allowResize) {
if (allowResize && !hasResizeEventRegistered) {
hasResizeEventRegistered = true;
global.addEventListener('resize', onResize, false);
}

Expand Down

0 comments on commit a07e811

Please sign in to comment.