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

Auto Save

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

              
                :ruby
  @items = [
    { :t => 'Angus Young', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-angus.png' },
    { :t => 'Aurora', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-aurora.png' },
    { :t => 'Bride of Frankenstein', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-bride.png' },
    { :t => 'Dracula', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-d.png' },
    { :t => 'Salvador Dalí', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-dali.png' },
    { :t => 'Ilhuicatl Xoxouhqui', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-huitzi.png' },
    { :t => "L'Homme qui rit", :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-man.png' },
    { :t => 'Visualization', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-v.png' },
    { :t => 'Visualization II', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-v2.png' },
    { :t => 'Visualization III', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-v3.png' },
    { :t => 'Zombie', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-worms.png' },
    { :t => 'X-Rays', :i => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/i-xrays.png' }    
  ]
 
%header.-center
  %h1 Direction Aware 3D Cube Animation <sup>v2</sup>
  %p.-neutral-mid No duplicated content (2 faces per “cube”)
%ul.-center
  - @items.each do | item |
    %li
      .w
        .f
          %svg{:viewBox => '0 0 180 180'}
            %image{'xlink:href' => "#{item[:i]}", :preserveAspectRatio => "xMidYMid slice", :width => '100%', :height => '100%'}
        .b
          %h3 
            #{item[:t]}
%footer.-center
  %p.-neutral-mid
    by 
    %a{:href => 'https://twitter.com/pixelia_me', :title => 'Noel Delgado', :target => '_blank'}
      %svg{:width => '28', :height => '16', :viewBox => '0 0 57 30'}
        %path{:d => 'M28.1312,9.5341 C29.7966,9.5341 32.1025,10.627 34.248,12.368 C49.3297,11.5836 53.8793,-0.4796 55.5773,0.6783 C57.8326,3.2476 50.8638,16.3535 39.4,19.088 C39.8655,20.2628 40.1364,21.4786 40.1364,22.6983 C40.1364,25.9478 38.837,26.7409 36.7281,28.8974 L36.704,28.824 C36.4799,29.0276 36.208,29.2318 35.8945,29.4 C35.8945,29.4 36.1346,27.0065 34.9341,26.7672 C34.9341,26.7672 34.3739,27.4054 33.0133,27.2459 C32.8532,25.8896 32.293,25.4109 32.1329,25.3311 C31.4126,25.4109 30.9324,26.5278 30.132,26.5278 C29.8,26.1969 29.5184,25.5615 29.312,24.972 C29.0201,25.4221 28.6036,26.1128 28.2512,26.2885 C27.8796,26.2885 27.1476,25.2858 26.836,24.832 C26.6262,25.4581 26.3285,26.1707 25.9702,26.5278 C25.1699,26.5278 24.6896,25.4109 23.9694,25.3311 C23.8093,25.4109 23.249,25.8896 23.089,27.2459 C21.7284,27.4054 21.1681,26.7672 21.1681,26.7672 C19.9676,27.0065 20.2077,29.4 20.2077,29.4 C19.6122,29.0804 19.1739,28.6307 18.908,28.304 L18.8667,28.3947 C17.1544,26.3262 16.1259,25.5896 16.1259,22.6983 C16.1259,21.4938 16.3637,20.2895 16.784,19.128 C5.2094,16.4922 -1.8448,3.2615 0.4227,0.6783 C2.119,-0.4785 6.6627,11.5578 21.708,12.364 C23.8143,10.6244 26.1724,9.5341 28.1312,9.5341 Z M28.8514,20.3048 C28.8514,20.3048 30.4121,21.7409 32.213,21.7409 C34.0137,21.7409 35.3343,19.3474 35.3343,19.3474 L28.8514,20.3048 Z M20.6879,19.3474 C20.6879,19.3474 22.2486,21.7409 24.0494,21.7409 C25.8502,21.7409 27.1707,20.3048 27.1707,20.3048 L20.6879,19.3474 Z', "fill-rule" => 'evenodd'}
              
            
!

CSS

              
                @use postcss-preset-env;
@import url(https://fonts.googleapis.com/css?family=Sahitya);

:root {
  --size: 180px;
  --gap: 5px;
  --tdeg: 90deg;
  --dr: 200ms;
  --tf: ease-out;
  --pr: 300px;
  --fr: #000;
  --bg: #fff;
  --mn: #00BCD4;
  --sc: #673AB7;
}

li {
  margin: var(--gap);
  position: relative;
  width: var(--size);
  height: var(--size);
  display: inline-block;
  vertical-align: top;
  perspective: var(--pr);
  transform-origin: 50% 50% calc(var(--size)/2);
}

.w {
  font-size: initial;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  transform-style: preserve-3d;
  transform-origin: 50% 50% calc(var(--size) / 2 * -1);
  will-change: transform;
  animation: var(--dr) var(--tf) 0ms 1 normal forwards paused;
}

.f,
.b {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  color: white;
  transition: none;
}

.f {
  background-color: var(--mn);
  background: linear-gradient(var(--mn), var(--sc));
  transform: translate3d(0,0,0);

  & > svg {
    mix-blend-mode: luminosity;
  }
}

.b {
  padding: 1rem;
  background-image: radial-gradient(circle, #333, #000 160%);
  transform: translate3d(0,0,-1px);

  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 20px 20px black;
  text-align: center;
}

.in-top .b,
.out-top .b {
  transform-origin: 0% 100%;
  transform: translate3d(0, -100%, 0) rotate3d(1,0,0,90deg);
}

.in-right .b,
.out-right .b {
  transform-origin: 0% 0%;
  transform: translate3d(100%, 0, 0) rotate3d(0,1,0,90deg);
}

.in-bottom .b,
.out-bottom .b {
  transform-origin: 0% 0%;
  transform: translate3d(0, 100%, 0) rotate3d(-1,0,0,90deg);
}

.in-left .b,
.out-left .b {
  transform-origin: 100% 0;
  transform: translate3d(-100%,0,0) rotate3d(0,-1,0,90deg);
}

.in-top .w    {animation-name: in-top; animation-play-state: running}
.in-right .w  {animation-name: in-right; animation-play-state: running}
.in-bottom .w {animation-name: in-bottom; animation-play-state: running}
.in-left .w   {animation-name: in-left; animation-play-state: running}

.out-top .w    {animation-name: out-top; animation-play-state: running}
.out-right .w  {animation-name: out-right; animation-play-state: running}
.out-bottom .w {animation-name: out-bottom; animation-play-state: running}
.out-left .w   {animation-name: out-left; animation-play-state: running}

@keyframes in-top {
  from  {transform: rotate3d(0,0,0,0deg)}
  to    {transform: rotate3d(-1,0,0,var(--tdeg))}
}
@keyframes out-top {
  from {transform: rotate3d(-1,0,0,var(--tdeg))}
  to   {transform: rotate3d(0,0,0,0deg)}
}

@keyframes in-right {
  from  {transform: rotate3d(0,0,0,0deg)}
  to    {transform: rotate3d(0,-1,0,var(--tdeg))}
}
@keyframes out-right {
  from  {transform: rotate3d(0,-1,0,var(--tdeg))}
  to    {transform: rotate3d(0,0,0,0deg)}
}

@keyframes in-bottom {
  from  {transform: rotate3d(0,0,0,0deg)}
  to    {transform: rotate3d(1,0,0,var(--tdeg))}
}
@keyframes out-bottom {
  from  {transform: rotate3d(1,0,0,var(--tdeg))}
  to    {transform: rotate3d(0,0,0,0deg)}
}

@keyframes in-left {
  from  {transform: rotate3d(0,0,0,0deg)}
  to    {transform: rotate3d(0,1,0,var(--tdeg))}
}
@keyframes out-left {
  from  {transform: rotate3d(0,1,0,var(--tdeg))}
  to    {transform: rotate3d(0,0,0,0deg)}
}

/* ======= aesthetics ======= */

* {
  margin: 0;
  box-sizing: border-box;
}

body {
  padding: 3rem 1.5rem;
  font-size: 16px;
  font-family: 'Sahitya', serif;
  color: var(--fr);
  background-color: var(--bg);
  line-height: 1.618;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header {
  padding-bottom: 3rem;
}

h1 {
  font-size: 2em;

  & sup {
    font-size: .7em;
    color: var(--mn);
  }
}

ul {
  font-size: 0;
  padding: 0;
  max-width: calc((var(--size) + (var(--gap) * 2)) * 4);
  margin: 0 auto;
  list-style: none;

  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

footer {
  font-size: .75rem;
  font-family: monospace;
  padding-top: 3rem;

  & a {
    display: inline-block;
    vertical-align: middle;
  }

  & svg {fill: currentColor}
}

:any-link {
  color: var(--mn);
}

.-center {
  text-align: center;
}

.-neutral-mid {
  color: color(var(--fr) tint(60%));
}
              
            
!

JS

              
                
// - Noel Delgado | @pixelia_me

class DAH {
  constructor(nodes) {
    this.nodes = [];

    Array.prototype.slice.call(nodes, 0).forEach(node => {
      this.nodes.push(new Node(node));
    });

    this._bindEvents();
  }

  _bindEvents() {
    ['_resizeHandler'].forEach(fn => this[fn] = this[fn].bind(this));
    window.addEventListener('resize', this._resizeHandler, false);
  }

  _resizeHandler() {
    this.nodes.forEach(node => node.update());
  }
}

class Node {
  constructor(node) {
    this.element = node;
    this._bindEvents().update();
  }

  update() {
    // const bcr = this.element.getBoundingClientRect();
    // this.l = bcr.left;
    // this.t = bcr.top;
    this.w = this.element.offsetWidth;
    this.h = this.element.offsetHeight;
    this.l = this.element.offsetLeft;
    this.t = this.element.offsetTop;
  }

  _bindEvents() {
    ['_mouseEnterHandler', '_mouseOutHandler'].forEach(fn => this[fn] = this[fn].bind(this));
    this.element.addEventListener('mouseenter', this._mouseEnterHandler, false);
    this.element.addEventListener('mouseout', this._mouseOutHandler, false);
    return this;
  }
  
  _mouseEnterHandler(ev) {
    this._addClass(ev, 'in');
  }

  _mouseOutHandler(ev) {
    this._addClass(ev, 'out');
  }

  _addClass(ev, state) {
    const direction = this._getDirection(ev);
    let class_suffix = '';

    switch (direction) {
      case 0: class_suffix = '-top'; break;
      case 1: class_suffix = '-right'; break;
      case 2: class_suffix = '-bottom'; break;
      case 3: class_suffix = '-left'; break;
    }

    this.element.className = '';
    this.element.classList.add(state + class_suffix);
  }

  _getDirection(ev) {
    const w = this.w,
      h = this.h,
      x = (ev.pageX - this.l - (w / 2) * (w > h ? (h / w) : 1)),
      y = (ev.pageY - this.t - (h / 2) * (h > w ? (w / h) : 1)),
      d = Math.round(Math.atan2(y, x) / 1.57079633 + 5) % 4;

    return d;
  }
}

new DAH(document.querySelectorAll('li'));
              
            
!
999px

Console