Skip to content

Commit

Permalink
Merge pull request #200 from catdad/#195-dedupe-resize-events
Browse files Browse the repository at this point in the history
registering only a single resize event
  • Loading branch information
catdad committed Sep 28, 2023
2 parents 2c028ea + a07e811 commit fb75303
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 fb75303

Please sign in to comment.