LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code



This Houdini demo requires the CSS Paint API and Typed OM.
Use Chrome and go to chrome://flags and enable Experimental Web Platform features.
Also make sure you're serving over https or localhost.
CSS
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0 20px;
  background-image: linear-gradient(to bottom, #70e1f5, #ffd194);
  font: 1rem/1.25 'Mukta Mahee', sans-serif;
}

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

.slot {
  display: flex;
  justify-content: center;
}

.placeholder {
  background-image: paint(placeholder-box-props);

  background-color: #fff;
  width: 120px;
  height: 120px;
  max-height: 100vh;
  overflow: auto;
  resize: both;
}

.slot:nth-child(1) .placeholder {
  border: 2px solid #fd7e14;
}

.slot:nth-child(2) .placeholder {
  border: 6px solid #228be6;
}

.slot:nth-child(3) .placeholder {
  border: 1rem solid #e64980;
}

.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;
}
JS
/*
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 PlaceholderBoxPropsPainter {
    static get inputProperties() {
      return ['border-top-width', 'border-top-color'];
    }

    paint(ctx, size, props) {
      // default values
      ctx.lineWidth = 2;
      ctx.strokeStyle = '#666';

      // set line width to top border width (if exists)
      let borderTopWidthProp = props.get('border-top-width');
      if (borderTopWidthProp) {
        ctx.lineWidth = borderTopWidthProp.value;
      }

      // set stroke style to top border color (if exists)
      let borderTopColorProp = props.get('border-top-color');
      if (borderTopColorProp) {
        ctx.strokeStyle = borderTopColorProp.toString();
      }

      // draw line from top left to bottom right
      ctx.beginPath();
      ctx.moveTo(0, 0);
      ctx.lineTo(size.width, size.height);
      ctx.stroke();

      // draw line from top right to bottom left
      ctx.beginPath();
      ctx.moveTo(size.width, 0);
      ctx.lineTo(0, size.height);
      ctx.stroke();
    }
  }

  registerPaint('placeholder-box-props', PlaceholderBoxPropsPainter);
}

Description

Uses input properties to match the element's border styles. Uses the Houdini CSS Paint API.
Term
Sat, 04/14/2018 - 20:42

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv