cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <script>
  if ('paintWorklet' in CSS && 'registerProperty' in CSS && 'CSSUnitValue' in window) {
    CSS.registerProperty({
      name: '--tooth-width',
      syntax: '<length>',
      initialValue: '40px'
    });
    CSS.registerProperty({
      name: '--tooth-height',
      syntax: '<length>',
      initialValue: '20px'
    });

    // load this CodePen's JS file as the paint worklet
    CSS.paintWorklet.addModule('/lonekorean/pen/zWOZyx.js');
  } else {
    document.querySelector('html').classList.add('no-support');
  }
</script>

<div class="container">
  <div class="slot">
    <div class="jagged"></div>
  </div>
  <div class="slot">
    <div class="jagged"></div>
  </div>
</div>

<div class="warning">
  <i class="fas fa-exclamation-triangle"></i><br>
  This Houdini demo requires the <strong>CSS Paint API</strong>, <strong>CSS Properties and Values API</strong>, and <strong>Typed OM</strong>.<br>
  Use <strong>Chrome</strong> and go to <strong>chrome://flags</strong> and enable <strong>Experimental Web Platform features</strong>.<br>
  Also make sure you're serving over <strong>https</strong> or <strong>localhost</strong>.
</div>

            
          
!
            
              *, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0 40px;
  background: #000;
  font: 1rem/1.25 'Mukta Mahee', sans-serif;
}

.container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 40px;
  align-items: center;
  height: 100%;
}

.slot {
  display: flex;
  justify-content: center;
  position: relative;
  height: 300px;
  border: 1px solid #fff;
  background-image: linear-gradient(to right, #444, #000);
}

.jagged {
  --tooth-width: 80px;
  --tooth-height: 30px;
  -webkit-mask-image: paint(jagged-edge);

  position: absolute;
  top: 30%;
  bottom: 0;
  width: 100%;
}

.slot:nth-child(1) .jagged {
  background-image: linear-gradient(to right, #22c1c3, #fdbb2d);
}

.slot:nth-child(2) .jagged {
  /* pixel art from Iconoclasts, fun game! http://www.playiconoclasts.com/ */
  background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/77020/iconoclasts.png');
  background-size: cover;
  background-position: 50% 0;
}

.warning {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  padding: 20px;
  border-top: 4px dashed #e8590c;
  background-color: #ffe8cc;
  color: #e8590c;
  text-align: center;
}

.no-support .warning {
  display: block;
}

.warning .fas {
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

            
          
!
            
              /*
This CodePen's JS file has been "hijacked" to serve as the paint worklet file. The if check below ensures the code only runs when referenced as such. JavaScript for the page is at the top of the HTML. I'm only doing this to squeeze everything into one CodePen.

IMPORTANT: If you fork, update the CodePen JS file path in the HTML.

ALSO IMPORTANT: If you edit code here, disable cache and reload. Live preview won't pick up changes in the paint worklet.
*/

if (typeof registerPaint !== 'undefined') {
  class JaggedEdgePainter {
    static get inputProperties() {
      return ['--tooth-width', '--tooth-height'];
    }

    paint(ctx, size, props) {
      let toothWidth = props.get('--tooth-width').value;
      let toothHeight = props.get('--tooth-height').value;

      // lots of math to ensure teeth are collectively centered
      let spaceBeforeCenterTooth = (size.width - toothWidth) / 2;
      let teethBeforeCenterTooth = Math.ceil(spaceBeforeCenterTooth / toothWidth);
      let totalTeeth = teethBeforeCenterTooth * 2 + 1;
      let startX = spaceBeforeCenterTooth - teethBeforeCenterTooth * toothWidth;

      // start drawing teeth from left
      ctx.beginPath();
      ctx.moveTo(startX, toothHeight);

      // draw the top zig-zag for all the teeth
      for (let i = 0; i < totalTeeth; i++) {
        let x = startX + toothWidth * i;
        ctx.lineTo(x + toothWidth / 2, 0);
        ctx.lineTo(x + toothWidth, toothHeight);
      }

      // surround the area below the teeth and fill it all in
      ctx.lineTo(size.width, size.height);
      ctx.lineTo(0, size.height);
      ctx.closePath();
      ctx.fill();
    }
  }

  registerPaint('jagged-edge', JaggedEdgePainter);
}

            
          
!
999px
Loading ..................

Console