Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better cleanup #57

Open
danmindru opened this issue May 22, 2023 · 1 comment
Open

Better cleanup #57

danmindru opened this issue May 22, 2023 · 1 comment

Comments

@danmindru
Copy link

hey Vladimir,
Thanks for the neat little lib!

Saw the implementation of clearCanvas() based on #46, but this is not exactly what @lifenautjoe was asking for, I think.

clearCanvas() removes the confetti but the canvases keep stacking. So if you have a button that shows confetti you'll get a bunch of empty canvases.

Maybe we need a destroyCanvas() or something like that? Alternatively clearCanvas() could also remove the canvas element from the DOM.
Happy to raise a PR if you want to get it in.

Screenshot 2023-05-22 at 10 47 23
@ghost
Copy link

ghost commented Jul 15, 2023

I fixed this using

React.useEffect(() => {
    setJsConfetti(new JSConfetti());
  }, []);

  function fire() {
    if (jsConfetti) {
      jsConfetti.addConfetti({
        emojis: ["✨", "💫", "🌈", "🍉"],
        emojiSize: 60,
        confettiNumber: 20,
      });
      // enable vibration support
      navigator.vibrate =
        navigator.vibrate ||
        navigator.webkitVibrate ||
        navigator.mozVibrate ||
        navigator.msVibrate;

      if (navigator.vibrate) {
        // vibration API supported
        navigator.vibrate(100);
      }
    }
    if (jsConfetti) {
      jsConfetti.addConfetti({
        emojis: ["✨", "💫", "🌈", "🍉"],
        emojiSize: 60,
        confettiNumber: 20,
      });
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant