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

              
                <!--Copyright at bottom -->

<div axis="random" duration="800" class="sc-card">
  <div class="umbra"></div>
  <div class="penumbra"></div>

  <div class="front" tabindex="-1">
    <h1>Supercharged</h1>
    <button>Flip card</button>
  </div>

  <div class="back" tabindex="-1">
    <button>Flip card</button>
  </div>
</div>


<!--
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
              
            
!

CSS

              
                /* Copyright at bottom */

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #E2E2E2;
    overflow: hidden;
}

.sc-card {
    width: 260px;
    height: 380px;
    position: relative;
    perspective: 500px;
    will-change: transform;
}

.sc-card .front,
.sc-card .back {
    backface-visibility: hidden;
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
}

.sc-card button {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: none;
    border: none;
    color: transparent;
    cursor: pointer;
}

.sc-card .front {
    background: #444;
    color: #FFF;
}

.sc-card .front h1 {
    font-size: 24px;
}

.sc-card .back {
    background: url('//cdn.rawgit.com/GoogleChrome/ui-element-samples/gh-pages/3d-card-flip/images/supercharged.jpg') center center no-repeat;
    color: #FFF;
    transform: rotateY(180deg);
}

.sc-card .umbra,
.sc-card .penumbra {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    backface-visibility: visible;
}

.sc-card .umbra {
    width: 270px;
    height: 390px;
    top: -5px;
    left: -5px;
    background: url('//cdn.rawgit.com/GoogleChrome/ui-element-samples/gh-pages/3d-card-flip/images/umbra.svg') center center no-repeat;
    transform: translateZ(-1px) translateY(2px);
    opacity: 0.3;
}

.sc-card .penumbra {
    width: 330px;
    height: 450px;
    top: -35px;
    left: -35px;
    background: url('//cdn.rawgit.com/GoogleChrome/ui-element-samples/gh-pages/3d-card-flip/images/penumbra.svg') center center no-repeat;
    transform: translateZ(-1px) translateY(2px);
    opacity: 0;
}

/**
 *
 * Copyright 2016 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
              
            
!

JS

              
                // Copyright at bottom
// From https://github.com/GoogleChrome/ui-element-samples/tree/gh-pages/3d-card-flip

// Modified to also support IE11, Edge, Firefox, Safari
// Custom element is not used and Web animations api polyfill is used


'use strict';

const log = console.log.bind(console);

class SCFlipCard { //extends HTMLElement {
  constructor(element) {
    // super();
    this.element = element;
    this.createdCallback();
    this.attachedCallback();
  }

  static get SIDES() {
    return {
      FRONT: 1,
      BACK: 2
    };
  }

  flip() {
    if (this._locked) {
      return;
    }

    this._locked = true;

    //const scale = (500 + 200) / 500; // 500 because css perspective is set to this value
    const scale = 1;

    const sideOne = [
      {transform: `translateZ(1px) rotate${this._axis}(0deg) scale(${scale})`},
      {transform: `translateZ(100px) rotate${this._axis}(0deg) scale(${scale})`, offset: 0.15},
      {transform: `translateZ(100px) rotate${this._axis}(180deg) scale(${scale})`, offset: 0.65},
      {transform: `translateZ(1px) rotate${this._axis}(180deg) scale(${scale})`}
    ];

    const sideTwo = [
      {transform: `translateZ(1px) rotate${this._axis}(180deg) scale(${scale})`},
      {transform: `translateZ(100px) rotate${this._axis}(180deg) scale(${scale})`, offset: 0.15},
      {transform: `translateZ(100px) rotate${this._axis}(360deg) scale(${scale})`, offset: 0.65},
      {transform: `translateZ(1px) rotate${this._axis}(360deg) scale(${scale})`}
    ];

    /*
     const sideOne = [
     {transform: `translateZ(-200px) rotate${this._axis}(0deg) scale(${scale})`},
     {transform: `translateZ(-100px) rotate${this._axis}(0deg) scale(${scale})`, offset: 0.15},
     {transform: `translateZ(-100px) rotate${this._axis}(180deg) scale(${scale})`, offset: 0.65},
     {transform: `translateZ(-200px) rotate${this._axis}(180deg) scale(${scale})`}
     ];

     const sideTwo = [
     {transform: `translateZ(-200px) rotate${this._axis}(180deg) scale(${scale})`},
     {transform: `translateZ(-100px) rotate${this._axis}(180deg) scale(${scale})`, offset: 0.15},
     {transform: `translateZ(-100px) rotate${this._axis}(360deg) scale(${scale})`, offset: 0.65},
     {transform: `translateZ(-200px) rotate${this._axis}(360deg) scale(${scale})`}
     ]; */

    const umbra = [
      {opacity: 0.3, transform: `translateY(2px) rotate${this._axis}(0deg)`},
      {opacity: 0.0, transform: `translateY(62px) rotate${this._axis}(0deg)`, offset: 0.15},
      {opacity: 0.0, transform: `translateY(62px) rotate${this._axis}(180deg)`, offset: 0.65},
      {opacity: 0.3, transform: `translateY(2px) rotate${this._axis}(180deg)`}
    ];

    const penumbra = [
      {opacity: 0.0, transform: `translateY(2px) rotate${this._axis}(0deg)`},
      {opacity: 0.5, transform: `translateY(62px) rotate${this._axis}(0deg)`, offset: 0.15},
      {opacity: 0.5, transform: `translateY(62px) rotate${this._axis}(180deg)`, offset: 0.65},
      {opacity: 0.0, transform: `translateY(2px) rotate${this._axis}(180deg)`}
    ];

    const timing = {
      duration: this._duration,
      iterations: 1,
      easing: 'ease-in-out',
      fill: 'forwards'
    };

    switch (this._side) {
      case SCFlipCard.SIDES.FRONT:
        this._front.animate(sideOne, timing);
        this._back.animate(sideTwo, timing);

        this._back.focus();
        this._front.inert = true;
        this._back.inert = false;
        break;

      case SCFlipCard.SIDES.BACK:
        this._front.animate(sideTwo, timing);
        this._back.animate(sideOne, timing);

        this._front.focus();
        this._front.inert = false;
        this._back.inert = true;
        break;

      default:
        throw new Error('Unknown side');
    }

    this._umbra.animate(umbra, timing);
    this._penumbra.animate(penumbra, timing)
      .onfinish = _ => {
      this._locked = false;
      this._side = (this._side === SCFlipCard.SIDES.FRONT) ?
        SCFlipCard.SIDES.BACK :
        SCFlipCard.SIDES.FRONT;
    };
  }

  createdCallback() {
    this._locked = false;
    this._side = SCFlipCard.SIDES.FRONT;
    this._front = this.element.querySelector('.front');
    this._back = this.element.querySelector('.back');
    this._buttons = this.element.querySelectorAll('button');
    this._umbra = this.element.querySelector('.umbra');
    this._penumbra = this.element.querySelector('.penumbra');

    this._front.inert = false;
    this._back.inert = true;

    this._duration = parseInt(this.element.getAttribute('duration'), 10);
    if (isNaN(this._duration)) {
      this._duration = 800;
    }

    this._axis = this.element.getAttribute('axis') || 'X';
    if (this._axis.toUpperCase() === 'RANDOM') {
      this._axis = (Math.random() > 0.5 ? 'Y' : 'X');
    }
  }

  attachedCallback() {
    [].slice.call(this._buttons)
      .forEach(b => {
        b.addEventListener('click', _ => this.flip());
      });
  }

  detachedCallback() {

  }
}


let card = new SCFlipCard(document.querySelector('.sc-card'));

// if(document.registerElement) document.registerElement('sc-card', SCFlipCard);


/**
 *
 * Copyright 2016 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

              
            
!
999px

Console