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

              
                   <div id="triangle"></div>

    <!-- Attribution -->
    <p class="attribution"><a target="_blank" href="http://lab.hakim.se/checkwave/">Triangular Version of Hakim El Hattab's Checkwave</a></p>

              
            
!

CSS

              
                /*
  All CSS By Hakim El Hattab
  https://github.com/hakimel/css/blob/master/checkwave/style.scss
  http://hakim.se/
*/

#triangle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
}

input {
  position: absolute;
  margin: 4px;
  padding: 0;
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}

input.grow {
  -webkit-animation: grow 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
     -moz-animation: grow 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
          animation: grow 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@-webkit-keyframes grow {
  0% { -webkit-transform: scale(1); }

  30% { -webkit-transform: scale(2.5); }

  100% { -webkit-transform: scale(1); }
}

@-moz-keyframes grow {
  0% { -moz-transform: scale(1); }

  30% { -moz-transform: scale(2.5); }

  100% { -moz-transform: scale(1); }
}

@keyframes grow {
  0% { transform: scale(1); }

  30% { transform: scale(2.5); }

  100% { transform: scale(1); }
}

p.attribution {
  margin: 0;
  padding: 0;
  position: absolute;
  right: 20px;
  bottom: 20px;
}
.attribution a {
  color: #333;
  font-family: 'PT Sans Narrow', sans-serif;
}
              
            
!

JS

              
                // -------------------------------------------------------------------
//  Based on the work of Hakim El Hattab
//  https://github.com/hakimel/css/blob/master/checkwave/index.html
// -------------------------------------------------------------------
var w, h, triangle, checkboxes;
var SQRT_3 = Math.pow(3, 0.5);

window.onload = function() {
  triangle = document.getElementById('triangle');
  buildTriangle();
};

window.onresize = function() {
  buildTriangle();
};

var buildTriangle = function() {
  var a = calcA();
  var h = SQRT_3 * 0.5 * a;
  var s = 20;
  var RES_X = Math.round(a / s);
  var RES_Y = Math.round(h / s);

  var xOff = 0;
  // See how many cheboxes we can fit in y direction
  // before the x count becomes zero
  RES_Y = calcYCount(RES_X, RES_Y);
  checkboxes = [];

  triangle.style.width = RES_X * s + 'px';
  triangle.style.height = RES_Y * s + 'px';

  // Remove all checkboxes if re-building
  while (triangle.firstChild) {
    triangle.removeChild(triangle.firstChild);
  }

  for (var y = RES_Y-1; y >= 0; y--) {
    for (var x = 0; x < RES_X; x++) {
      buildCheckBox(x * s + xOff, y * s);
    }

    RES_X = (RES_X === 2) ? RES_X -= 1 : RES_X -= 2;
    xOff = (RES_X === 1) ? xOff += s * 0.5 : xOff += s;
  }
};

var calcYCount = function(RES_X, RES_Y) {
  var yCount = 0;
  for (var y = RES_Y-1; y >= 0; y--) {
    if (RES_X > 0) yCount++;
    RES_X = (RES_X === 2) ? RES_X -= 1 : RES_X -= 2;
  }
  return yCount;
};

var buildCheckBox = function(x, y) {
  var el = document.createElement('input');
  el.setAttribute('type', 'checkbox');
  triangle.appendChild(el);

  var checkbox = {
    el: el,
    x: x,
    y: y
  };

  el.style.left = checkbox.x + 'px';
  el.style.top = checkbox.y + 'px';
  el.addEventListener('change', this.toggle.bind(this, checkbox));

  checkboxes.push(checkbox);
};

var calcA = function() {
  w = window.innerWidth * 2 / 3;
  h = window.innerHeight * 2 / 3;
  return Math.min(w, h);
};

var map = function (n, start1, stop1, start2, stop2) {
  return (n - start1) / (stop1 - start1) * (stop2 - start2) + start2;
};

var toggle = function (targetCheckbox) {
  var checked = targetCheckbox.el.checked;

  checkboxes.forEach(function(checkbox) {

    var dx = targetCheckbox.x - checkbox.x;
    var dy = targetCheckbox.y - checkbox.y;
    var distance = Math.sqrt( dx * dx + dy * dy );

    setTimeout(function() {
      checkbox.el.checked = checked;

      // re-run the animation, reading offsetWidth forces reflow
      checkbox.el.className = '';
      checkbox.el.offsetWidth;
      checkbox.el.className = 'grow';
    }, Math.round( distance * 1.8 ) );
  });
};

setTimeout( function() {
  checkboxes[0].el.checked = true;
  toggle(checkboxes[0]);
}, 500);
              
            
!
999px

Console