Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!-- Cactus from https://www.freepik.com/free-vector/enjoyable-cacti-set_853959.htm -->
<svg viewBox="0 -5 157.9 210">
  <style>
    .st1{fill:#d78d40}.st6,.st8{fill:#587434}.st8{clip-path:url(#SVGID_8_)}.st11{fill:#e8a2c1}.st12{fill:#a4466d}.st14{fill:#e35c98}.st15{fill:#1c2816}.st16{fill:#f2f6dc}
  </style>
  <ellipse cx="89.3" cy="192.1" rx="68.6" ry="13.1" fill="#efdbc7"/>
  <g>
    <path class="st1" d="M12.2 131.5c2.3 8 10.9 52.7 15 58.5s34.8 10.4 48.7 10.4 41.2-2.4 45.8-7.4 17.9-61.5 17.9-61.5H12.2z"/>
    <g>
      <defs>
        <path id="SVGID_4_" d="M12.2 131.5c2.3 8 10.9 52.7 15 58.5s34.8 10.4 48.7 10.4 41.2-2.4 45.8-7.4 17.9-61.5 17.9-61.5H12.2z"/>
      </defs>
      <clipPath id="SVGID_5_">
        <use xlink:href="#SVGID_4_" overflow="visible"/>
      </clipPath>
      <path d="M157.3 107.8c.4-7.8-41.4-16.6-73.4-19.1-29-2.2-73.4 1.9-81.4 8.6-.5.3-.8.7-1.1 1.3-.1.3-.2.5-.2.8-.7 5.1.6 36.7 4.4 42.5 3.8 5.8 35.8 15.3 70.8 17.2 34.1 1.8 58.6-5.6 63.7-8.8 5.2-3.2 17.3-28.4 17.2-42.5z" clip-path="url(#SVGID_5_)" fill="#d78d40"/>
    </g>
    <path class="st1" d="M156.3 97.5c0-7.8-42.3-14.4-74.3-15.1-29.1-.6-73.1 5.8-80.8 13-.5.3-.8.7-1 1.3-.1.3-.2.5-.2.8-.4 5.1 2.6 36.6 6.7 42.2S43.4 153 78.4 153c34.2 0 58.2-8.8 63.2-12.2 4.9-3.4 15.6-29.2 14.7-43.3z"/>
    <g>
      <defs>
        <path id="SVGID_3_" d="M156.3 97.5c0-7.8-42.3-14.4-74.3-15.1-29.1-.6-73.1 5.8-80.8 13-.5.3-.8.7-1 1.3-.1.3-.2.5-.2.8-.4 5.1 2.6 36.6 6.7 42.2S43.4 153 78.4 153c34.2 0 58.2-8.8 63.2-12.2 4.9-3.4 15.6-29.2 14.7-43.3z"/>
      </defs>
      <clipPath id="SVGID_6_">
        <use xlink:href="#SVGID_3_" overflow="visible"/>
      </clipPath>
      <path d="M8.2 98c0-6.4 40.2-17.3 70.2-16.7 0 0-83.5-9.3-78.2 15.5-3.2 23.2 90.5 32.1 119.3 18.4-37.1-1-111.3-8.8-111.3-17.2z" clip-path="url(#SVGID_6_)" fill="#deb387"/>
    </g>
    <path d="M4.5 98.1c0 8.2 30.9 21.9 73.7 21.9s73.8-14.8 74-21.6c.1-5.1-41.3-13.6-70.5-14.3-29.2-.6-77.2 7.7-77.2 14z" fill="#573a1c"/>
    <g>
      <defs>
        <path id="SVGID_2_" d="M4.5 98.1c0 8.2 30.9 21.9 73.7 21.9s73.8-14.8 74-21.6c.1-5.1-41.3-13.6-70.5-14.3-29.2-.6-77.2 7.7-77.2 14z"/>
      </defs>
      <clipPath id="SVGID_7_">
        <use xlink:href="#SVGID_2_" overflow="visible"/>
      </clipPath>
      <path d="M4.5 107.1c0 8.2 30.9 21.9 73.7 21.9s73.8-14.8 74-21.6c.1-5.1-41.3-13.6-70.5-14.3-29.2-.6-77.2 7.7-77.2 14z" clip-path="url(#SVGID_7_)" fill="#2d1c0f"/>
    </g>
  </g>
  <g class="cactus">
    <g class="hidden">
      <path class="st6" d="M16.8 91.3c-2.4-.1-8.7 4.1-8.3 5.3.4 1.3 8.3 1.6 9.2 1 2.9-1.7 1.2-5.5-.9-6.3z"/>
      <path class="st6" d="M15.3 60.9c-2.2-1-9.6.4-9.7 1.6-.2 1.4 7 4.7 8.1 4.6 3.3-.5 3.2-4.7 1.6-6.2z"/>
      <path class="st6" d="M35.5 28.4c-1.4-1.9-8.6-4.3-9.3-3.3-.8 1.1 3.8 7.5 4.8 7.9 3.1 1.1 5.1-2.5 4.5-4.6z"/>
      <path class="st6" d="M65.4 14.9c.3-2.4-3.2-9.1-4.4-8.8-1.4.2-2.5 8.1-2 9.1 1.4 2.9 5.4 1.7 6.4-.3z"/>
      <path class="st6" d="M133.6 49.4c2.4-.3 7.9-5.4 7.4-6.5-.6-1.3-8.4-.3-9.3.4-2.5 2.1-.2 5.7 1.9 6.1z"/>
      <path class="st6" d="M136.6 88.8c2.2.8 9.5-1.2 9.6-2.4 0-1.4-7.4-4.1-8.4-3.9-3.2.7-2.9 4.9-1.2 6.3z"/>
    </g>
    <path d="M75.9 117.3c29.4.1 41.5-5.8 48.8-8.8 7.3-3 14.7-16.3 14-34.7-.7-18.3-6.5-48.9-45.3-58C34.3 1.9 14.6 54.5 14.2 65.4c-.5 11.5-.1 25 5.8 35.2 4.8 8.4 15.3 11.5 24.1 13.3 10.5 2.2 21.1 3.3 31.8 3.4z" fill="#7ba640"/>
    <g>
      <defs>
        <path id="SVGID_1_" d="M75.9 117.3c29.4.1 41.5-5.8 48.8-8.8 7.3-3 14.7-16.3 14-34.7-.7-18.3-6.5-48.9-45.3-58C34.3 1.9 14.6 54.5 14.2 65.4c-.5 11.5-.1 25 5.8 35.2 4.8 8.4 15.3 11.5 24.1 13.3 10.5 2.2 21.1 3.3 31.8 3.4z"/>
      </defs>
      <clipPath id="SVGID_8_">
        <use xlink:href="#SVGID_1_" overflow="visible"/>
      </clipPath>
      <path class="st8" d="M19.1 104.7c37.8 14.5 63.3 9.8 80.8 4 12.8-4.2 19.4-20.3 20.2-33.9 1-17-7.2-36.3-8.8-39.7-19.2 1.8-29.8-7.2-31.8-12.3-2-5 27.5-5.3 30.4-4.7 3 .6 36.3 30.1 38.8 38.3s-.5 52.1-8 58.4-49.7 12.7-64.2 10.9c-46.5-5.7-57.4-21-57.4-21z"/>
      <path d="M99.7 124.1c6.3-2 20.7-11.3 27.7-24.9 4.9-9.4 6.5-28.5 2.5-42.5 1 16.2 2.3 27.4-4.8 40.8-5.9 11.3-13.8 20.9-39.3 23.9 3.2 1.5 13.9 2.7 13.9 2.7z" clip-path="url(#SVGID_8_)" fill="#7ba640"/>
      <path class="st8" d="M97.7 117.2c6.5-3.6 14.5-15.3 17.2-32 2.1-13.4.7-31-5.3-42.9 1.2 11.8 3.6 27.5 0 41.9-4 15.8-9.7 24.5-36.2 29.9 9.2 3.6 24.3 3.1 24.3 3.1z"/>
      <path class="st8" d="M66.3 117.7c-6.1-1.1-29-3.5-33.3-23.9-2.8-13.6-.4-26.7 4.7-41.7-7.2 10.6-9.9 27-8.3 41.5C31 108 39 114.2 44.8 117.2c3.2 1.7 21.5.5 21.5.5z"/>
      <path d="M30.8 29C40.4 18.3 68.6 6 68.6 6l18.5 12.9.3 2.1c-.4 0-1.4 3.6-4.2 2.2-13.4 1.7-32 19-35.5 33.4 5.7-20.3 9.5-26.1 19.2-33-15.2 3.9-34.3 18.9-39 43.5.8-16.8 13.5-37.5 23.4-42.3-22.6 7.3-36 36.1-32.1 60.9C14 72.1 14.6 47.3 30.8 29z" clip-path="url(#SVGID_8_)" fill="#98b54d"/>
    </g>
    <g>
      <path class="st11" d="M92.4 19.3c2.7.1 6-8.8 5.2-15.1-.9-6.7-20.8-3-20.1 1.1.6 4 9.8 13.7 14.9 14z"/>
      <g>
        <g>
          <g>
            <path class="st12" d="M82.8 2.1c.9-.3 2.6-.7 4.7-.9 2.1-.2 4.5-.3 6.6.3 1.1.3 2 .8 2.5 1.5.3.4.4.8.5 1.2.1.5.1.9.2 1.3.1 1.6.1 2.6.3 2.6.1 0 .4-1 .4-2.7 0-.4 0-.9-.1-1.3-.1-.5-.2-1.1-.6-1.6-.6-1-1.8-1.6-2.9-2-2.3-.7-4.9-.7-7-.5-2.1.2-3.9.7-4.9.9-.5.1-1.2.3-2 .7-.8.3-1.7.7-2.6 1.5-.4.4-.9.9-1 1.7 0 .4.1.7.2 1l.3.9c.5 1.3 1.2 2.3 1.9 3.2 2.9 3.8 6.3 6.2 6.5 6 .2-.2-3-2.9-5.7-6.6-.7-.9-1.3-1.9-1.7-2.9-.1-.3-.2-.5-.3-.8-.1-.2-.2-.5-.1-.6 0-.3.3-.7.7-1 .7-.6 1.6-1 2.3-1.3.7-.3 1.3-.5 1.8-.6z"/>
          </g>
        </g>
      </g>
      <path class="st11" d="M87.4 21c1.2-2.4-7.7-18.3-10.9-16.7-1.7.9-7.1 6.3-5.4 10.1 2.1 4.9 14.3 10.4 16.3 6.6z"/>
      <g>
        <g>
          <g>
            <path class="st12" d="M73.2 8.2c.4-.6 1.3-1.6 2.5-2.6.3-.2.6-.5.9-.7.2-.1.3-.1.4-.2.1 0 .3 0 .4.1.7.2 1.4.8 2 1.4 2.4 2.5 4.1 5.2 4.3 5 .2-.1-1.2-3-3.6-5.7-.6-.7-1.3-1.3-2.3-1.7-.3-.1-.5-.1-.9-.1-.3 0-.6.2-.8.3-.4.2-.8.5-1.1.8-1.3 1.1-2.1 2.2-2.6 2.8-.5.6-1.4 1.8-1.9 3.4-.2.8-.4 1.8-.2 2.8.2 1 .8 1.8 1.4 2.5 1.2 1.4 2.7 2.4 3.8 3 1.1.6 1.9.9 1.9.8.1-.1-.6-.6-1.6-1.3-1-.7-2.3-1.7-3.4-3-.5-.6-1-1.4-1.2-2.1-.2-.8 0-1.5.2-2.3.6-1.5 1.4-2.6 1.8-3.2z"/>
          </g>
        </g>
      </g>
      <path class="st11" d="M98.4 2c-4.5.7-7.8 15.6-3.3 17.4 4.5 1.8 18 4 22.5-.8S106.1.8 98.4 2z"/>
      <g>
        <g>
          <g>
            <path class="st12" d="M112.2 8.4c.9.8 2.6 2.3 4.1 4.3.7 1 1.5 2.3 1.6 3.6.1.6-.1 1.3-.4 1.7-.4.5-.9 1-1.5 1.3-2.4 1.4-5.2 1.7-7.2 1.8-2 .1-3.3.1-3.3.3 0 .1 1.3.4 3.3.4 2 0 4.9-.2 7.7-1.7.7-.4 1.3-.8 1.8-1.5s.7-1.6.7-2.4c-.1-.8-.3-1.6-.7-2.2-.3-.7-.7-1.3-1.1-1.8-1.6-2.2-3.4-3.7-4.3-4.5-1-.8-2.8-2.2-5.1-3.5-1.2-.7-2.5-1.3-3.9-1.8s-2.9-.8-4.5-.8c-.4 0-.8 0-1.2.1-.4.1-.8.3-1.1.5-.6.5-1.1 1-1.5 1.6C94.8 4.9 94.3 6 94 7c-.6 2-.7 3.3-.6 3.3.2 0 .5-1.2 1.2-3.1.4-.9.9-2 1.6-3 .4-.5.8-1 1.3-1.3.3-.2.5-.3.8-.4.3-.1.6-.1 1-.1 2.8 0 5.6 1.3 7.9 2.5 2.3 1.3 4 2.7 5 3.5z"/>
          </g>
        </g>
      </g>
      <path d="M94.6 21.2c2.3 1.2 9.1 2.5 8.3-1.6s-11.7-9-14.8-6.9c-3.1 2.2 1.7 6 6.5 8.5z" fill="#e8dc75"/>
      <path class="st14" d="M118.4 16.9c1.4 5.6-1 9.6-8.4 12.1s-16.6 1.5-17.9-2.8c.8-4.1 8.7-6.4 15.8-6.9 4.9-.4 9.8-5.4 10.5-2.4z"/>
      <g>
        <g>
          <g>
            <path class="st12" d="M117.6 24.8c.5-.6 1-1.4 1.3-2.6.4-1.2.4-2.6.2-4.1 0-.4-.1-.7-.2-1.1-.1-.4-.2-1-.8-1.3-.6-.3-1.1-.2-1.5-.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.3-.1 1.8.6 3.3 1.3 4.5.7 1.3 1.6 2.3 2.3 3.1 1.5 1.6 2.8 2.4 2.8 2.3.1-.1-1-1-2.3-2.7-.7-.8-1.4-1.9-2.1-3.1-.6-1.2-1.2-2.6-1-4 .1-.7.4-1.2.9-1.6.6-.4 1.3-.5 2-.6 1.5-.1 3 0 4.4.3 3 .4 5.2 1.2 6.5 1.7z"/>
          </g>
        </g>
      </g>
    </g>
    <g>
      <g class="open-eyes">
        <path class="st15" d="M107.6 76.1c6.4 0 3.9 17-1.9 16s-4.1-16 1.9-16z"/>
        <circle class="st16" cx="108.7" cy="81.3" r="2"/>
        <path class="st15" d="M45.9 76.1c-6.4 0-3.9 17 1.9 16s4.1-16-1.9-16z"/>
        <circle class="st16" cx="47.8" cy="81.3" r="2"/>
      </g>
      <path d="M90.2 95.9c1.5 1.4-3.5 12.7-14.9 12.5-11.4-.3-14.9-10.9-13.9-12.5 1.6-2.6 25.6-2.9 28.8 0z" fill="#36150f"/>
      <path class="st11" d="M65.1 104.3c2.3 2.2 5.6 4 10.2 4.1 3.9.1 7-1.2 9.4-2.9-2.5-1.4-5.9-2.7-10.2-2.7-4 0-7.1.6-9.4 1.5z"/>
    </g>
    <path class="st15 closed-eye" d="M112.2 82c-.8-1.8-2.5-3.3-4.5-3.5-4.2-.4-7.6 4.9-7.3 8.6 0 .6.9.8 1.2.3 1.3-2.3 2.4-6.6 5.7-6.6 4.1 0 2.5 4.8 4 7 .3.4.9.6 1.2.1 1.1-1.6.5-4.2-.3-5.9z"/>
    <path class="st15 closed-eye" d="M40.4 82c.8-1.8 2.5-3.3 4.5-3.5 4.2-.4 7.6 4.9 7.3 8.6 0 .6-.9.8-1.2.3-1.3-2.3-2.4-6.6-5.7-6.6-4.1 0-2.5 4.8-4 7-.3.4-.9.6-1.2.1-1.1-1.6-.5-4.2.3-5.9z"/>
  </g>
</svg>

              
            
!

CSS

              
                body {
  overflow: hidden;
  background: white;
  touch-action: none;
}
svg {
  position: fixed;
  left: 50%;
  bottom: 0;
  height: 50vh;
  transform: translate(-50%);
  z-index: 1;
  touch-action: none;
  -wekbit-user-select:none;
  user-select:none;
  -webkit-tap-highlight-color:rgba(0,0,0,0);
  .closed-eye {
    opacity: 0;
  }
  .cactus {
    cursor: pointer;
    transform-origin: 88px 106px;
    transition: 0.3s cubic-bezier(0,1.06,.82,1.55);
  }
  &:active {
    .open-eyes {
      opacity: 0;
    }
    .closed-eye {
      opacity: 1;
    }
  }
}
.particle {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  background-size: contain;
  background-repeat: no-repeat;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='6.5' height='10.9' viewBox='0 0 6.5 10.9'><path d='M6.4 9.2C7 6.9 4.2-.1 2.9 0 1.6.1-.3 7.8 0 8.8c1.2 3.1 5.3 2.3 6.4.4z' fill='%23587434'/></svg>");
}
              
            
!

JS

              
                let amountSpines = 0;
let spinesinterval = null;
const cactus = document.querySelector('.cactus');
let x = 0;
let y = 0;
document.querySelector('svg').addEventListener('mousedown', () => {
  amountSpines = 0;
  mousedown = true;
  cactus.style.transition = 'none';
  requestAnimationFrame(increaseSpines);
});
document.querySelector('svg').addEventListener('mouseup', (e) => {
  x = e.clientX;
  y = e.clientY;
  pop(e);
  mousedown = false;
  cactus.style.transform = 'scale(1)';
  cactus.style.transition = '';
});
document.querySelector('svg').addEventListener('touchstart', (e) => {
  console.log('start')
  amountSpines = 0;
  mousedown = true;
  cactus.style.transition = 'none';
  x = e.touches[0].clientX;
  y = e.touches[0].clientY;
  requestAnimationFrame(increaseSpines);
});
document.querySelector('svg').addEventListener('touchend', (e) => {
  console.log('end')
  pop(e);
  mousedown = false;
  cactus.style.transform = 'scale(1)';
  cactus.style.transition = '';
});

function increaseSpines () {
  if (mousedown && amountSpines < 200) {
    requestAnimationFrame(increaseSpines);
    amountSpines += 2;
    cactus.style.transform = `scale(${(200 - amountSpines) / 200 * 0.2 + 0.8})`;
  }
}

function pop (e) {
  for (let i = 0; i < Math.min(amountSpines, 200); i++) {
    // We call the function createParticle 30 times
    // As we need the coordinates of the mouse, we pass them as arguments
    createParticle(e);
  }
}

function createParticle (e) {
  const particle = document.createElement('span');
  particle.classList.add('particle');
  document.body.appendChild(particle);
  
  const size = Math.floor(Math.random() * 30 + 10);
  particle.style.width = `${size * 0.6}px`;
  particle.style.height = `${size}px`;
  particle.style.filter = `brightness(${Math.random() + 0.5})`;
  
  // Generate a random x & y destination within a distance of 75px from the mouse
  const destinationX = x + (Math.random() - 0.5) * 2 * (innerWidth * 0.5);
  const destinationY = y + (Math.random() - 0.8) * 2 * (innerHeight * 0.5);
  const rotate = Math.atan2(destinationY - y, destinationX - x) * 180 / Math.PI + 90;

  particle.animate({
      transform: [`translate(${x}px, ${y}px) rotate(${rotate}deg)`, `translate(${destinationX}px, ${destinationY}px) rotate(${rotate}deg)`],
      opacity: [1, 1, 0],
      offset: [0, 0.7]
    }, {
    duration: Math.random() * 1000 + 800,
    easing: 'cubic-bezier(0, .9, .57, 1)',
    delay: Math.random() * 200,
    fill: 'backwards'
  })
  .onfinish = () => particle.remove();
}

// iOs hack
document.addEventListener("touchstart", function() {},false);
              
            
!
999px

Console