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

Save Automatically?

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 id="firework"></div>

<div class="task-item">
    <label class="checkbox">
        <input value="2020" type="checkbox" />
        <svg viewBox="0 0 21 18">
            <symbol id="tick-path" viewBox="0 0 21 18" xmlns="http://www.w3.org/2000/svg">
                <path d="M5.22003 7.26C5.72003 7.76 7.57 9.7 8.67 11.45C12.2 6.05 15.65 3.5 19.19 1.69" fill="none" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" />
            </symbol>
            <defs>
                <mask id="tick">
                    <use class="tick mask" href="#tick-path" />
                </mask>
            </defs>
            <path class="shape" d="M1.08722 4.13374C1.29101 2.53185 2.53185 1.29101 4.13374 1.08722C5.50224 0.913124 7.25112 0.75 9 0.75C10.7489 0.75 12.4978 0.913124 13.8663 1.08722C15.4681 1.29101 16.709 2.53185 16.9128 4.13374C17.0869 5.50224 17.25 7.25112 17.25 9C17.25 10.7489 17.0869 12.4978 16.9128 13.8663C16.709 15.4681 15.4682 16.709 13.8663 16.9128C12.4978 17.0869 10.7489 17.25 9 17.25C7.25112 17.25 5.50224 17.0869 4.13374 16.9128C2.53185 16.709 1.29101 15.4681 1.08722 13.8663C0.913124 12.4978 0.75 10.7489 0.75 9C0.75 7.25112 0.913124 5.50224 1.08722 4.13374Z" />
            <use class="tick" href="#tick-path" stroke="currentColor" />
            <path fill="#2C2C31" mask="url(#tick)" d="M4.03909 0.343217C5.42566 0.166822 7.20841 0 9 0C10.7916 0 12.5743 0.166822 13.9609 0.343217C15.902 0.590152 17.4098 2.09804 17.6568 4.03909C17.8332 5.42566 18 7.20841 18 9C18 10.7916 17.8332 12.5743 17.6568 13.9609C17.4098 15.902 15.902 17.4098 13.9609 17.6568C12.5743 17.8332 10.7916 18 9 18C7.20841 18 5.42566 17.8332 4.03909 17.6568C2.09805 17.4098 0.590152 15.902 0.343217 13.9609C0.166822 12.5743 0 10.7916 0 9C0 7.20841 0.166822 5.42566 0.343217 4.03909C0.590151 2.09805 2.09804 0.590152 4.03909 0.343217Z" />
        </svg>
        <svg class="lines" viewBox="0 0 11 11">
            <path d="M5.88086 5.89441L9.53504 4.26746" />
            <path d="M5.5274 8.78838L9.45391 9.55161" />
            <path d="M3.49371 4.22065L5.55387 0.79198" />
        </svg>
    </label>
    <div class="text">2020</a></div>
    <button class="flag">
        <svg viewBox="0 0 18 18">
            <path d="M7.66 16.75L2.25 2C8 -0.249996 9.5 3.50001 14 1.75C15.5 4.25002 16 8.00002 15.5 9C11 11 9.5 8.50002 5.03377 9.58975" />
            <path class="fill" d="M7.66 16.75L2.25 2C8 -0.249996 9.5 3.50001 14 1.75C15.5 4.25002 16 8.00002 15.5 9C11 11 9.5 8.50002 5.03377 9.58975" />
        </svg>
    </button>
</div>

<div class="task-item">
    <label class="checkbox">
        <input value="2021" type="checkbox" />
        <svg viewBox="0 0 21 18">
            <symbol id="tick-path-1" viewBox="0 0 21 18" xmlns="http://www.w3.org/2000/svg">
                <path d="M5.22003 7.26C5.72003 7.76 7.57 9.7 8.67 11.45C12.2 6.05 15.65 3.5 19.19 1.69" fill="none" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" />
            </symbol>
            <defs>
                <mask id="tick-1">
                    <use class="tick mask" href="#tick-path-1" />
                </mask>
            </defs>
            <path class="shape" d="M1.08722 4.13374C1.29101 2.53185 2.53185 1.29101 4.13374 1.08722C5.50224 0.913124 7.25112 0.75 9 0.75C10.7489 0.75 12.4978 0.913124 13.8663 1.08722C15.4681 1.29101 16.709 2.53185 16.9128 4.13374C17.0869 5.50224 17.25 7.25112 17.25 9C17.25 10.7489 17.0869 12.4978 16.9128 13.8663C16.709 15.4681 15.4682 16.709 13.8663 16.9128C12.4978 17.0869 10.7489 17.25 9 17.25C7.25112 17.25 5.50224 17.0869 4.13374 16.9128C2.53185 16.709 1.29101 15.4681 1.08722 13.8663C0.913124 12.4978 0.75 10.7489 0.75 9C0.75 7.25112 0.913124 5.50224 1.08722 4.13374Z" />
            <use class="tick" href="#tick-path-1" stroke="currentColor" />
            <path fill="#2C2C31" mask="url(#tick-1)" d="M4.03909 0.343217C5.42566 0.166822 7.20841 0 9 0C10.7916 0 12.5743 0.166822 13.9609 0.343217C15.902 0.590152 17.4098 2.09804 17.6568 4.03909C17.8332 5.42566 18 7.20841 18 9C18 10.7916 17.8332 12.5743 17.6568 13.9609C17.4098 15.902 15.902 17.4098 13.9609 17.6568C12.5743 17.8332 10.7916 18 9 18C7.20841 18 5.42566 17.8332 4.03909 17.6568C2.09805 17.4098 0.590152 15.902 0.343217 13.9609C0.166822 12.5743 0 10.7916 0 9C0 7.20841 0.166822 5.42566 0.343217 4.03909C0.590151 2.09805 2.09804 0.590152 4.03909 0.343217Z" />
        </svg>
        <svg class="lines" viewBox="0 0 11 11">
            <path d="M5.88086 5.89441L9.53504 4.26746" />
            <path d="M5.5274 8.78838L9.45391 9.55161" />
            <path d="M3.49371 4.22065L5.55387 0.79198" />
        </svg>
    </label>
    <div class="text">2021</div>
    <button class="flag">
        <svg viewBox="0 0 18 18">
            <path d="M7.66 16.75L2.25 2C8 -0.249996 9.5 3.50001 14 1.75C15.5 4.25002 16 8.00002 15.5 9C11 11 9.5 8.50002 5.03377 9.58975" />
            <path class="fill" d="M7.66 16.75L2.25 2C8 -0.249996 9.5 3.50001 14 1.75C15.5 4.25002 16 8.00002 15.5 9C11 11 9.5 8.50002 5.03377 9.58975" />
        </svg>
    </button>
</div>
              
            
!

CSS

              
                #firework {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

.task-item {
    --text-color: #fff;
    --text-line-scale: 0;
    --text-x: 0px;
    --border-default: #7F7F85;
    --border-hover: #E4E4E7;
    --checkbox-active: #6E7BF2;
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    width: 340px;
    border-radius: 7px;
    overflow: hidden;
    -webkit-mask-image: -webkit-radial-gradient(white, black);
    transition: background .15s linear;
    &:not(.done) {
        &:hover {
            --blur-x: 372px;
            --blur-o: 1;
            background: #2C2C31;
        }
    }
    &:before {
        content: '';
        position: absolute;
        width: 32px;
        height: 6px;
        right: 100%;
        top: -11px;
        border-radius: 50%;
        box-shadow: 0px 4px 4px var(--checkbox-active);
        transform: translateX(var(--blur-x, 0));
        opacity: var(--blur-o, 0);
        transition: opacity .15s, transform 1.2s;
    }
    &.done {
        --checkbox-active: #444449;
        --flag-border: #444449;
        --text-color: #626268;
    }
    .text {
        display: block;
        letter-spacing: -.05px;
        text-decoration: none;
        color: var(--text-color);
        position: relative;
        transform: translateX(var(--text-x)) translateZ(0);
        transition: color .25s;
        &:before {
            content: '';
            position: absolute;
            height: 1px;
            left: -2px;
            right: -2px;
            top: 50%;
            transform-origin: 0 50%;
            transform: translateY(-50%) scaleX(var(--text-line-scale)) translateZ(0);
            background: currentColor;
        }
    }
    .checkbox {
        --active-tick: #ffffff;
        --checkbox-lines-offset: 13.5px;
        display: block;
        padding: 15px 12px;
        cursor: pointer;
        position: relative;
        -webkit-tap-highlight-color: transparent;
        svg {
            display: block;
            position: absolute;
        }
        input {
            display: block;
            outline: none;
            border: none;
            background: none;
            padding: 0;
            margin: 0;
            -webkit-appearance: none;
            width: 18px;
            height: 18px;
            & + svg {
                width: 21px;
                height: 18px;
                left: 12px;
                top: 15px;
                color: var(--checkbox-active);
                transition: color .25s linear;
                .shape {
                    stroke-width: 1.5px;
                    stroke: var(--border, var(--border-default));
                    fill: var(--background, none);
                    transition: fill .25s linear, stroke .25s linear;
                }
                .tick {
                    stroke-dasharray: 20;
                    stroke-dashoffset: var(--checkbox-tick-offset, 20px);
                    transition: stroke-dashoffset var(--checkbox-tick-duration, .15s) var(--checkbox-tick-easing, ease);
                    &.mask {
                        stroke: var(--active-tick);
                    }
                }
                & + svg {
                    width: 11px;
                    height: 11px;
                    fill: none;
                    stroke: var(--checkbox-active);
                    stroke-width: 1.25;
                    stroke-linecap: round;
                    top: 9px;
                    right: 2px;
                    stroke-dasharray: 4.5px;
                    stroke-dashoffset: var(--checkbox-lines-offset);
                    pointer-events: none;
                }
            }
            &:checked {
                & + svg {
                    --background: var(--checkbox-active);
                    --border: var(--checkbox-active);
                    --checkbox-tick-duration: .2s;
                    --checkbox-tick-easing: cubic-bezier(0, .45, 1, .5);
                    --checkbox-tick-offset: 0;
                }
            }
        }
        &:hover {
            input {
                &:not(:checked) {
                    & + svg {
                        --border: var(--border-hover);
                    }
                }
            }
        }
    }
    .flag {
        --flag-color: #BABAC1;
        --flag-fill: var(--checkbox-active);
        --flag-fill-percent: 0%;
        --flag-scale-x: 1;
        --flag-scale-y: 1;
        --flag-rotate: 0deg;
        --flag-circle-opacity: 0;
        --flag-circle-scale: 0;
        -webkit-appearance: none;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
        outline: none;
        border: none;
        background: none;
        padding: 15px 12px;
        margin: 0 0 0 auto;
        position: relative;
        &.active {
            --flag-fill-percent: 150%;
        }
        svg {
            display: block;
            width: 18px;
            height: 18px;
            position: relative;
            z-index: 1;
            pointer-events: none;
            fill: none;
            stroke: var(--flag-border, var(--border, var(--border-default)));
            stroke-width: 1.5;
            stroke-linecap: round;
            stroke-linejoin: round;
            transform-origin: 7.66px 16.75px;
            transform: scale(var(--flag-scale-x), var(--flag-scale-y)) rotate(var(--flag-rotate));
            transition: stroke .25s linear;
            .fill {
                stroke: var(--flag-fill);
                fill: var(--flag-fill);
                clip-path: circle(var(--flag-fill-percent) at var(--flag-fill-x, 7.66px) var(--flag-fill-y, 16.75px));
                transition: fill .25s linear, stroke .25s linear;
            }
        }
        &:hover {
            --border: var(--border-hover);
        }
        &:before {
            content: '';
            display: block;
            width: 24px;
            height: 12px;
            border-radius: 50%;
            position: absolute;
            bottom: 6px;
            left: 8px;
            opacity: var(--flag-circle-opacity);
            background: var(--flag-fill);
            transform: scale(var(--flag-circle-scale)) translateZ(0);
        }
    }
}

html {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

* {
    box-sizing: inherit;
    &:before,
    &:after {
        box-sizing: inherit;
    }
}

// Center & dribbble
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #242428;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
              
            
!

JS

              
                const { to, set, registerPlugin } = gsap;

const checkAudio = new Audio("https://assets.codepen.io/165585/check.mp3");
const flagAudio = new Audio("https://assets.codepen.io/165585/flag-2.mp3");

registerPlugin(MorphSVGPlugin);

document.querySelectorAll(".task-item").forEach((task) => {
  let checkbox = task.querySelector(".checkbox"),
    checkboxInput = checkbox.querySelector("input"),
    flag = task.querySelector(".flag"),
    flagPath = flag.querySelectorAll("path"),
    timer;

  checkboxInput.addEventListener("change", (e) => {
    clearInterval(timer);
    if (e.target.value == "2020") {
      if (!Renderer.initialised) {
        Renderer.init();
      }
      Renderer.toggle();
    }
    if (e.target.checked) {
      checkAudio.play();
      to(checkbox, {
        "--checkbox-lines-offset": "4.5px",
        duration: 0.2,
        delay: 0.2,
        clearProps: true,
      });
      to(task, {
        keyframes: [
          {
            "--text-line-scale": 1,
            "--text-x": "2px",
            duration: 0.15,
          },
          {
            "--text-x": "0px",
            duration: 0.15,
            onComplete() {
              timer = setTimeout(() => task.classList.add("done"), 500);
            },
          },
        ],
      });
      return;
    }
    to(task, {
      "--text-line-scale": 0,
      duration: 0.25,
      onComplete() {
        task.classList.remove("done");
      },
    });
  });

  flag.addEventListener("pointerenter", (e) => {
    flag.animating;
    if (flag.animating) {
      return;
    }
    to(flag, {
      keyframes: [
        {
          "--flag-rotate": e.offsetX > 21 ? "-4deg" : "4deg",
          duration: 0.1,
        },
        {
          "--flag-rotate": e.offsetX > 21 ? "4deg" : "-4deg",
          duration: 0.1,
        },
        {
          "--flag-rotate": "0deg",
          duration: 0.1,
        },
      ],
    });
  });

  flag.addEventListener("click", (e) => {
    if (flag.animating) {
      return;
    }
    flag.animating = true;

    if (flag.classList.contains("active")) {
      to(flag, {
        keyframes: [
          {
            "--flag-scale-y": 0.9,
            "--flag-fill-percent": "0%",
            duration: 0.15,
          },
          {
            "--flag-scale-y": 1,
            duration: 0.25,
          },
        ],
        onComplete() {
          flag.classList.remove("active");
          flag.animating = false;
        },
      });
      return;
    }

    flagAudio.play();

    to(flagPath, {
      duration: 1.8,
      ease: "sine.out",
      keyframes: new Array(2)
        .fill([
          {
            morphSVG:
              "M7.66 16.75L2.25 1.99999C8 0.5 9.5 2.54999 14 0.799988C15.5 3.3 16.5 7.00001 16 8C11.5 10 9.5 9.58974 5.03377 9.58974",
          },
          {
            morphSVG:
              "M7.66 16.75L2.25 2.00001C9.5 4.50001 9 1 14.5 2C16 4.50001 16 8.00002 15.5 9.00001C10 10.5 9.5 9 5.03377 9.58976",
          },
          {
            morphSVG:
              "M7.66 16.75L2.25 2C7 2.75 9.5 1.50001 14 1.75C15.5 4.25001 16 8.00001 15.5 9C11 9 9.5 10.5 5.03377 9.58975",
          },
          {
            morphSVG:
              "M7.66 16.75L2.25 2C8 -0.249996 9.5 3.50001 14 1.75C15.5 4.25002 16 8.00002 15.5 9C11 11 9.5 8.50002 5.03377 9.58975",
          },
        ])
        .flat(),
    });

    to(flag, {
      "--flag-fill-percent": "150%",
      duration: 0.25,
      delay: 0.2,
      clearProps: true,
      onStart() {
        set(flag, {
          "--flag-fill-x": "1.5px",
          "--flag-fill-y": "1.5px",
        });
      },
      onComplete() {
        flag.classList.add("active");
        flag.animating = false;
      },
    });
  });
});

const fireworkAudio = new Audio(
  "https://assets.codepen.io/165585/firework.mp3"
);

const fireworkStartAudio = new Audio(
  "https://assets.codepen.io/165585/firework-start.mp3"
);

const Renderer = {
  initialised: false,
  play: false,
  interval: { min: 20, max: 200 },
  background: "hsla(240, 5%, %luminance%, 1)",
  init() {
    this.initialised = true;
    this.setParameters();
    this.reconstructMethod();
    this.render();
  },
  toggle() {
    this.play = !this.play;
  },
  setParameters() {
    this.container = document.querySelector("#firework");
    this.width = this.container.offsetWidth;
    this.height = this.container.offsetHeight;
    this.distance = Math.sqrt(
      Math.pow(this.width / 2, 2) + Math.pow(this.height / 2, 2)
    );
    this.resolution = window.devicePixelRatio || 1;
    this.canvas = document.createElement("canvas");
    this.canvas.width = this.width * this.resolution;
    this.canvas.height = this.height * this.resolution;
    this.context = this.canvas.getContext("2d");
    this.container.appendChild(this.canvas);
    this.canvas.style.width = this.width + "px";
    this.canvas.style.height = this.height + "px";
    this.context.scale(this.resolution, this.resolution);

    this.fireworks = [new Firework(this.width, this.height, this)];

    this.maxFireworkInterval = this.getRandomValue(this.interval) | 0;
    this.fireworkInterval = this.maxFireworkInterval;
  },
  reconstructMethod() {
    this.render = this.render.bind(this);
  },
  getRandomValue(range) {
    return range.min + (range.max - range.min) * Math.random();
  },
  render() {
    requestAnimationFrame(this.render);

    var maxOpacity = 0,
      context = this.context;

    for (var i = this.fireworks.length - 1; i >= 0; i--) {
      maxOpacity = Math.max(maxOpacity, this.fireworks[i].getOpacity());
    }
    context.fillStyle = this.background.replace("%luminance", 15 + maxOpacity);
    context.fillRect(0, 0, this.width, this.height);

    for (var i = this.fireworks.length - 1; i >= 0; i--) {
      if (!this.fireworks[i].render(context)) {
        this.fireworks.splice(i, 1);
      }
    }

    if(!this.play) {
      return
    }

    if (--this.fireworkInterval == 0) {
      this.fireworks.push(new Firework(this.width, this.height, this));
      this.maxFireworkInterval = this.getRandomValue(this.interval) | 0;
      this.fireworkInterval = this.maxFireworkInterval;
    }
  },
};

const Firework = function (width, height, renderer) {
  this.width = width;
  this.height = height;
  this.renderer = renderer;
  this.init();
};

Firework.prototype = {
  color: "hsl(%hue, 84%, 69%)",
  particleCount: 300,
  delta: { opacity: 0.01, theta: Math.PI / 10 },
  radius: 2,
  velocity: -3,
  wait: { min: 20, max: 40 },
  threshold: 50,
  gravity: 0.002,
  init() {
    this.setParameters();
    this.createParticles();
  },
  setParameters() {
    var hue = (256 * Math.random()) | 0;

    this.x = this.renderer.getRandomValue({
      min: this.width / 8,
      max: (this.width * 7) / 8,
    });
    this.y = this.renderer.getRandomValue({
      min: this.height / 4,
      max: this.height / 2,
    });
    this.x0 = this.x;
    this.y0 = this.height + this.radius;
    this.color = this.color.replace("%hue", hue);
    this.status = 0;
    this.init = 0;
    this.theta = 0;
    this.waitCount = this.renderer.getRandomValue(this.wait);
    this.opacity = 1;
    this.velocity = this.velocity;
    this.particles = [];
  },
  createParticles() {
    for (var i = 0, length = this.particleCount; i < length; i++) {
      this.particles.push(new Particle(this.x, this.y, this.renderer));
    }
  },
  getOpacity() {
    return this.status == 2 ? this.opacity : 0;
  },
  render(context) {
    switch (this.status) {
      case 0:
        context.save();
        context.fillStyle = this.color;
        context.globalCompositeOperation = "lighter";
        context.globalAlpha =
          this.y0 - this.y <= this.threshold
            ? (this.y0 - this.y) / this.threshold
            : 1;
        context.translate(this.x0 + Math.sin(this.theta) / 2, this.y0);
        context.scale(0.8, 2.4);
        context.beginPath();
        context.arc(0, 0, this.radius, 0, Math.PI * 2, false);
        context.fill();
        context.restore();

        this.y0 += this.velocity;

        if (this.y0 <= this.y) {
          this.status = 1;
        }

        if(this.init === 0) {
          this.init = 1
          fireworkStartAudio.cloneNode(true).play();
        }

        this.theta += this.delta.theta;
        this.theta %= Math.PI * 2;
        this.velocity += this.gravity;
        return true;
      case 1:
        if (--this.waitCount <= 0) {
          this.status = 2;
        }
        return true;
      case 2:
        if (this.opacity === 1) {
          fireworkAudio.cloneNode(true).play();
        }
        context.save();
        context.globalCompositeOperation = "lighter";
        context.globalAlpha = this.opacity;
        context.fillStyle = this.color;

        for (var i = 0, length = this.particles.length; i < length; i++) {
          this.particles[i].render(context, this.opacity);
        }
        context.restore();
        this.opacity -= this.delta.opacity;

        return this.opacity > 0;
    }
  },
};

const Particle = function (x, y, renderer) {
  this.x = x;
  this.y = y;
  this.renderer = renderer;
  this.init();
};

Particle.prototype = {
  radius: 1.5,
  velocity: { min: 0, max: 3 },
  gavity: 0.03,
  friction: 0.98,
  init() {
    var radian = Math.PI * 2 * Math.random(),
      velocity = (1 - Math.pow(Math.random(), 6)) * this.velocity.max,
      rate = Math.random();

    this.vx = velocity * Math.cos(radian) * rate;
    this.vy = velocity * Math.sin(radian) * rate;
  },
  render(context, opacity) {
    context.beginPath();
    context.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
    context.fill();

    this.x += this.vx;
    this.y += this.vy;
    this.vy += this.gavity;
    this.vx *= this.friction;
    this.vy *= this.friction;
  },
};

              
            
!
999px

Console