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 class="frame">
  <div class="content">
    <h1>Paper simulation</h1>
    <h2>Checkbox <a href="http://www.polymer-project.org/components/paper-elements/demo.html#paper-checkbox">original <i class="fa fa-external-link"></i></a></h2>
    <input type="checkbox" data-label="Notifications"/>
    <input type="checkbox" checked="checked" data-label="Auto-updates"/>

    <h2>Radio button <a href="http://www.polymer-project.org/components/paper-elements/demo.html#paper-radio-button">original <i class="fa fa-external-link"></i></a></h2>
    <input type="radio" name="sex" value="male" checked="checked" data-label="Male"/>
    <input type="radio" name="sex" value="female" data-label="Female"/>
    <input type="radio" name="sex" value="other" data-label="Other"/>
    
    <p>Supports IE8+, Chrome, Safari, Opera, Firefox</p>
    <p>For IE8 add 'ie8' class to html element to try, actually tested with an xp/ie8 VM. Without round or rotate everything is replaced by icons from font-awesome</p>
  </div>
  <div class="author"><a href="https://ggaulard.github.io">Guillaume Gaulard <i class="fa fa-external-link"></i></a></div>
</div>
              
            
!

CSS

              
                // sass(scss), autoprefixer, bootstrap

$material-radio-unselected-color: #844236;
$material-radio-selected-color: #cb844e;
$material-checkbox-unselected-color: #844236;
$material-checkbox-selected-color: #cb844e;

//////////////////////////////////////////////////////////////////////////////
/////////// COMMON CHECKBOX AND RADIO EFFECT /////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
.material.checkbox, .material.radio {
  cursor: pointer;
  font-size: 12pt;
  display: block;
  overflow: hidden;
  position: relative;
  min-height: 55px;
  padding: 15px 0px 3px 56px;
  font-weight: normal;
  
  .circle {
    border-radius: 50%;
    display: block;
    height: 51px;
    width: 51px;
    top: 1px;
    left: 2px;
    opacity: 1;
    position: absolute;
    z-index:0;
    overflow: hidden;
    background-color: #fff;
    
    transition: all 0.3s ease-in-out;
  }
  
  input[type='checkbox'], input[type='radio'] {
     position: absolute;
     z-index: -1;
     top:13px;
     left:40px;
  }
}

//////////////////////////////////////////////////////////////////////////////
/////////// RADIO EFFECT /////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
.material.radio {  
  .input-fake-circle-empty {
    border: 2px solid $material-radio-unselected-color;
    border-radius: 50%;
    color: #1d1d1d;
    cursor: pointer;
    position:absolute;
    z-index:1;
    height: 14px;
    width: 14px;
    margin: auto;
    top: 0; left: 0; bottom: 0; right: 0;
  }
  
  .input-fake-circle-full {
    border-radius: 50%;
    cursor: pointer;
    position:absolute;
    z-index:2;
    background-color: $material-radio-selected-color;
    margin: auto;
    top: 0; left: 0; bottom: 0; right: 0;
  }
  
  .input-fake-circle-full.show.static { 
    height: 18px;
    width: 18px;
  }
  
  .input-fake-circle-full.show.animate {     
    animation-name: material-input-radio-show;
  }
  
  .input-fake-circle-full.hide.static { 
    height: 0px;
    width: 0px;
    display: block !important;
  }

  .input-fake-circle-full.hide.animate { 
    animation-name: material-input-radio-hide;
  }
  
  .animate {
    animation-duration: 0.3s;
    animation-fill-mode: forwards;
  }
}

.ie8{
  .material.radio{
    .input-fake-circle-empty{
      display: none !important;
    }
    
    .input-fake-circle-full{
      font-family: "FontAwesome";
      font-style: normal;
      font-weight: 400;
      line-height: 1;
      font-smoothing: antialiased;
      border: 0px;
      background-color: transparent;
      top:-13px !important;
      left:-13px !important;
      height: 0px !important;
      width: 0px !important;
    }
    
    .input-fake-circle-full:before{
      position: absolute;
    }
    
    .input-fake-circle-full.show:before{
      content: "\f111";
      color:$material-radio-selected-color;
    }
    
    .input-fake-circle-full.hide:before{
      content: "\f10c";
      color:$material-radio-unselected-color;
    }
  }
}

// fake radio hide
@keyframes material-input-radio-hide {
  0% {
    height: 18px;
    width: 18px;
  }
  100% {
    height: 0px;
    width: 0px;
  }
}

// fake radio show
@keyframes material-input-radio-show {
  0% {
    height: 0px;
    width: 0px;
  }
  100% {
    height: 18px;
    width: 18px;
  }
}

//////////////////////////////////////////////////////////////////////////////
/////////// CHECKBOX EFFECT //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
.material.checkbox {  
  .input-fake-box {
    border: 2px solid $material-checkbox-unselected-color;
    cursor: pointer;
    position:absolute;
    z-index:2;
  }
  
  .input-fake-box.show.static { 
    opacity: 1;
    height: 14px;
    width: 14px;
    top: 19px;
    left: 19px;
    transform: rotate(0);
  }
  
  .input-fake-box.show.animate {   
    animation-name: material-input-checkbox-fake-box-show;
  }

  .input-fake-box.hide.static { 
    opacity: 0;
    height: 0px;
    width: 0px;
    top: 33px;
    left: 26px;
    transform: rotate(-45deg);
    display: block !important;
  }
  
  .input-fake-box.hide.animate {    
    animation-name: material-input-checkbox-fake-box-hide;
  }
  
  .input-fake-check {
    cursor: pointer;
    position:absolute;
    z-index:2;
    
    border-left: 2px solid $material-checkbox-selected-color;
    border-bottom: 4px solid $material-checkbox-selected-color;
    border-top: 1px solid rgba(0,0,0,0);
    border-right: 1px solid rgba(0,0,0,0);    
    transform: rotate(-45deg) scaleY(0.5);
  }
  
  .input-fake-check.show.static { 
    opacity: 1;
    top: 17px;
    left: 20px;
    height: 14px;
    width: 14px;
  }
  
  .input-fake-check.show.animate {     
    animation-name: material-input-checkbox-fake-check-show;
  }
  
  .input-fake-check.hide.static { 
    opacity: 0;
    top: 29px;
    left: 25px;
    height: 0px;
    width: 0px;
    display: block !important;
  }

  .input-fake-check.hide.animate { 
    animation-name: material-input-checkbox-fake-check-hide;
  }
  
  .animate {
    animation-duration: 0.3s;
    animation-fill-mode: forwards;
  }
}

.ie8{
  .material.checkbox{
    .input-fake-check.hide{
      display: none !important;
    }
    
    .input-fake-box.hide{
      display: none !important;
    }
    
    .input-fake-check.show{
      font-family: "Glyphicons Halflings";
      font-style: normal;
      font-weight: 400;
      line-height: 1;
      -webkit-font-smoothing: antialiased;
      border: 0px;
      
      // not need in ie8 but keep a littre clean if ie8 activated out of ie8
      transform: rotate(0) scaleY(1);
    }
    
    .input-fake-check.show:before{
      content: "\e013";
      color:$material-checkbox-selected-color;
      left: -3px;
      position: absolute;
    }
  }
}

// fake checkbox box hide
@keyframes material-input-checkbox-fake-box-hide {
  0% {
    opacity: 1;
    height: 14px;
    width: 14px;
    top: 19px;
    left: 19px;
    transform: rotate(0);
  }
  60% {
    opacity: 1;
  }
  61% {
    opacity: 0;
  }
  100% {
    opacity: 0;
    height: 0px;
    width: 0px;
    top: 33px;
    left: 26px;
    transform: rotate(-45deg);
  }
}

// fake checkbox box show
@keyframes material-input-checkbox-fake-box-show {
  0% {
    opacity: 0;
    height: 0px;
    width: 0px;
    top: 33px;
    left: 26px;
    transform: rotate(-45deg);
  }
  10% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    height: 14px;
    width: 14px;
    top: 19px;
    left: 19px;
    transform: rotate(0);
  }
}

// fake checkbox check hide
@keyframes material-input-checkbox-fake-check-hide {
  0% {
    opacity: 1;
    top: 17px;
    left: 20px;
    height: 14px;
    width: 14px;
  }
  60% {
    opacity: 1;
  }
  61% {
    opacity: 0;
  }
  100% {
    opacity: 0;
    top: 29px;
    left: 25px;
    height: 0px;
    width: 0px;
  }
}

// fake checkbox check show
@keyframes material-input-checkbox-fake-check-show {
  0% {
    opacity: 0;
    top: 29px;
    left: 25px;
    height: 0px;
    width: 0px;
  }
  10% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    top: 17px;
    left: 20px;
    height: 14px;
    width: 14px;
  }
}

//////////////////////////////////////////////////////////////////////////////
/////////// RIPPLE EFFECT ////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
.material .circle{
  .ink {
    display: block;
    position: absolute;
    pointer-events: none;
    border-radius: 50%;
    transform: scale(0);
    background: #dfdfdf;
    opacity: 1;
  }

  .ink.show {
    animation: material-circle-ripple-ink-show .3s forwards;
  }
  
  .ink.hide {
    display: block !important;
    animation: material-circle-ripple-ink-hide .3s forwards;
  }
}

.ie8{
  .material .circle{
    .ink{
      display: none !important;
    }
  }
}

//down
@keyframes material-circle-ripple-ink-show {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  100% {
    opacity: 1;
    transform: scale(2.5);
  }
}

// up
@keyframes material-circle-ripple-ink-hide {
  0% {
    opacity: 1;
    transform: scale(2.5);
  }
  100% {
    opacity: 0;
    transform: scale(2.5);
  }
}
              
            
!

JS

              
                var materialFramework = {}

/*****************************************************************************
 * RADIO *********************************************************************
 *****************************************************************************/
materialFramework.radio = {
  /**
   * Init
   */
  init : function(){  
    // wrap inputs
    $('input[type="radio"]').each(function(){
      var $input = $(this);
      $input.wrap('<label class="material radio">'+$input.attr('data-label')+'</label>');
    });
    
    // add elements require for animations
    $(".material.radio").append('<span class="circle">'+
                                     '<span class="input-fake-circle-empty"></span>'+
                                     '<span class="input-fake-circle-full static"></span>'+
                                     '</span>');

    // add classes and listeners required for animations
    $(".material.radio").each(function(){
      var $this = $(this);
      var $input = $this.children("input[type='radio']");
      var $inputFakeCircle = $this.find('.input-fake-circle-full');

      // define correct state of simulated checkbox
      materialFramework.radio.updateFakeElementClasses($input, $inputFakeCircle);
      
      // on orignal checkbox change update simulated one
      $input.change(function(e){
          var $input = $(this);
          materialFramework.radio.onMaterialInputChange($input);
      });
    });
  },
  
  /**
   * Update state of simulated radio element with current state of original radio
   */
  updateFakeElementClasses : function($input, $inputFakeCircle){
    if($input.prop('checked')){    
      $inputFakeCircle.removeClass('hide');
      $inputFakeCircle.addClass('show');
    }else{
      $inputFakeCircle.removeClass('show');
      $inputFakeCircle.addClass('hide');
    }
  },
  
  /**
   * When the original checkbox change his state update the simulated one with animation
   */
  onMaterialInputChange : function($input){
    var $parent = $input.parent();
    var $inputFakeCircle = $parent.find('.input-fake-circle-full');

    $('input[name="'+$input.attr('name')+'"]').each(function(){
      var $this = $(this);
      
      if($this.attr('value') != $input.attr('value')){
        materialFramework.radio.updateFakeElementClasses($this, $this.parent().find('.input-fake-circle-full'));
      }
    });
    
    materialFramework.radio.updateFakeElementClasses($input, $inputFakeCircle);

    $inputFakeCircle.addClass('animate');
  }
}

/*****************************************************************************
 * CHECKBOX ******************************************************************
 *****************************************************************************/
materialFramework.checkbox = {
  
  /**
   * Init
   */
  init : function(){
    // wrap inputs
    $('input[type="checkbox"]').each(function(){
      var $input = $(this);
      $input.wrap('<label class="material checkbox">'+$input.attr('data-label')+'</label>');
    })
    
    // add elements require for animations
    $(".material.checkbox").append('<span class="circle">'+
                                     '<span class="input-fake-box static"></span>'+
                                     '<span class="input-fake-check static"></span>'+
                                     '</span>');
    
    // add classes and listeners required for animations
    $(".material.checkbox").each(function(){
      var $this = $(this);
      var $input = $this.children("input[type='checkbox']");
      var $inputFakeBox = $this.find('.input-fake-box');
      var $inputFakeCheck = $this.find('.input-fake-check');

      // define correct state of simulated checkbox
      materialFramework.checkbox.updateFakeElementClasses($input, $inputFakeBox, $inputFakeCheck);
      
      // on orignal checkbox change update simulated one
      $input.change(function(e){
          var $input = $(this);
          materialFramework.checkbox.onMaterialInputChange($input);
      });
    });
  },
  
  /**
   * Update state of simulated checkbox element with current state of original checkbox
   */
  updateFakeElementClasses : function($input, $inputFakeBox, $inputFakeCheck, hasDelayToShow){
    var toShow = $inputFakeBox;
    var toHide = $inputFakeCheck;
    
    if($input.prop('checked')){    
      toShow = $inputFakeCheck;
      toHide = $inputFakeBox;
    }
    
    toHide.removeClass('show');
    toHide.addClass('hide');

    toShow.removeClass('hide');
    if(hasDelayToShow && !ie8){
      setTimeout(function(){
        toShow.addClass('show');
      }, 200);
    }else{
      toShow.addClass('show');
    }
  },
  
  /**
   * When the original checkbox change his state update the simulated one with animation
   */
  onMaterialInputChange : function($input){
    var $parent = $input.parent();
    var $inputFakeBox = $parent.find('.input-fake-box');
    var $inputFakeCheck = $parent.find('.input-fake-check');

    if($input.prop('checked')){    
      $inputFakeBox.removeClass('delay');
      $inputFakeCheck.addClass('delay');
    }else{
      $inputFakeBox.addClass('delay');
      $inputFakeCheck.removeClass('delay');
    }

    materialFramework.checkbox.updateFakeElementClasses($input, $inputFakeBox, $inputFakeCheck, true);

    $inputFakeBox.addClass('animate');
    $inputFakeCheck.addClass('animate');
  }
}

/*****************************************************************************
 * RIPPLE FOR ELEMENT WITH A CIRCLE ******************************************
 *****************************************************************************/
materialFramework.rippleCircle = {
  
  /**
    * Init
    */
  init : function(){    
    // add ripple effet on mouse down
    $(".material .circle").mousedown(function(e){
      var rippler = $(this);

      // create .ink element if it doesn't exist
      if(rippler.find(".ink").length == 0) {
        rippler.append("<span class='ink'></span>");
      }

      var ink = rippler.find(".ink");

      // prevent quick double clicks
      ink.removeClass("show");

      // set .ink diametr
      if(!ink.height() && !ink.width()) {
        var d = Math.max(rippler.outerWidth(), rippler.outerHeight());
        ink.css({height: d, width: d});
      }

      // get click coordinates
      var x = e.pageX - rippler.offset().left - ink.width()/2;
      var y = e.pageY - rippler.offset().top - ink.height()/2;

      ink.removeClass('hide');
      
      // set .ink position and add class .animate
      ink.css({
        top: y+'px',
        left:x+'px'
      }).addClass("show");
      
      materialFramework.rippleCircle.animating = new Date().getTime();
    });

    // remove ripple mouse down effet on mouse up or out
    var removeRippleEffect = function(){
      var lastShow = new Date().getTime() - materialFramework.rippleCircle.animating;
      var rippler = $(this);

      if(lastShow > 300){
        materialFramework.rippleCircle.hideRippler(rippler);
      }else{
        setTimeout(function(){
          materialFramework.rippleCircle.hideRippler(rippler);
        }, 300-lastShow);
      }
    }

    $(".material .circle").mouseup(removeRippleEffect);
    $(".material .circle").mouseout(removeRippleEffect);
  },
  
  hideRippler: function(rippler){
    var ink = rippler.find(".ink");
    ink.addClass("hide");
  }
}

/*****************************************************************************
 * START MATERIEL DESIGN *****************************************************
 *****************************************************************************/
var ie8 = $('html.ie8').length != 0;
materialFramework.radio.init();
materialFramework.checkbox.init();
materialFramework.rippleCircle.init();
              
            
!
999px

Console