Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="backdrop"></div>
<div class="dialog w-70 text-center">
  <div class="relative z-10086 flex justify-between w-full space-x-12">
    <div class="emitter order-1"></div>
    <div class="emitter order-3"></div>
    <div class="emitter order-2 -top-6"></div>
  </div>
  <div class="text-lg font-bold">Congratulations!</div>
  <div class="mt-4">You win the game!</div>
  <button class="mt-4 btn btn-primary" onclick="start();">Again</button>
</div>
              
            
!

CSS

              
                body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.z-10086 {
  z-index: 10086;
}

.-top-6 {
  top: -6rem;
}

.emitter {
  position: relative;

  div {
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 4px;
    background: var(--particle-color);
  }
}

              
            
!

JS

              
                gsap.registerPlugin(Physics2DPlugin);
const emitters = document.querySelectorAll(".emitter");
const turn = 360;
const sample = (arr) => arr[Math.floor(Math.random() * arr.length)];
const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));
const makeParticles = (
  emitter,
  quantity,
  x,
  y,
  minAngle,
  maxAngle,
  minVelocity,
  maxVelocity,
  gravity
) => {
  let colors = ["#4ec0e9", "#ffce52", "#ed5464", "#8e44ad", "#2ecc71"];
  for (let i = quantity - 1; i >= 0; i--) {
    const angle = gsap.utils.random(minAngle, maxAngle);
    const velocity = gsap.utils.random(minVelocity, maxVelocity);
    const particle = document.createElement("div");
    particle.style.setProperty("--particle-color", sample(colors));
    emitter.appendChild(particle);
    gsap.set(particle, {
      opacity: 0,
      scale: gsap.utils.random(0.3, 0.8),
      x,
      y
    });
    const t1 = gsap.timeline({
      onComplete() {
        particle.remove();
      }
    });
    t1.to(
      particle,
      {
        opacity: 1,
        duration: 0.05
      },
      0
    )
      .to(
        particle,
        {
          rotationX: `+=${gsap.utils.random(2 * turn, 4 * turn)}`,
          rotationZ: `+=${gsap.utils.random(2 * turn, 4 * turn)}`,
          physics2D: {
            angle,
            velocity,
            gravity
          },
          duration: 2
        },
        0
      )
      .to(
        particle,
        {
          opacity: 0,
          duration: 1
        },
        0.8
      );
  }
};

const start = async () => {
  for (const emitter of emitters) {
    makeParticles(emitter, 100, -4, 6, 0, 360, 60, 120, 60);
    await sleep(500);
  }
};

start();

              
            
!
999px

Console