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

              
                <!-- normal -->
<div class='wrapper'>
  <div class='checkbox'>
    <label>
      <input type='checkbox' value='Toggle Mee' checked />
      <span>Toggle Mee</span>
    </label>
  </div>
  <div class='checkbox'>
    <label>
      <input type='checkbox' value='Hokkien Mee' />
      <span>Hokkien Mee</span>
    </label>
  </div>
  <div class='checkbox'>
    <label>
      <input type='checkbox' value='Bak Chor Mee' />
      <span>Bak Chor Mee</span>
    </label>
  </div>
  <div class='checkbox'>
    <label>
      <input type='checkbox' value='Mee Goreng' />
      <span>Mee Goreng</span>
    </label>
  </div>
</div>

<!-- icons only -->
<div class='wrapper'>
  <div class='checkbox no-label 2ndrow'>
    <input type='checkbox' value='301' />
  </div>
  <div class='checkbox no-label 2ndrow'>
    <input type='checkbox' value='302' checked />
  </div>
  <div class='checkbox no-label 2ndrow'>
    <input type='checkbox' value='303' checked />
  </div>
  <div class='checkbox no-label 2ndrow'>
    <input type='checkbox' value='304' checked />
  </div>
  <div class='checkbox no-label 2ndrow'>
    <input type='checkbox' value='305' />
  </div>
  <div class='checkbox no-label 2ndrow'>
    <input type='checkbox' value='306' />
  </div>
  <div class='checkbox no-label 2ndrow'>
    <input type='checkbox' value='307' />
  </div>
  <div class='checkbox no-label 2ndrow'>
    <input type='checkbox' value='308' />
  </div>
</div>

<div class='wrapper'>
  <button class='initCheckbox'><span>Convert Checkboxes</span></button>
  
  <div class='checkbox toggleAll' data-role='toggle' data-classgroup='checkbox'>
    <label>
      <input type='checkbox' value='Toggle All' />
      <span>Toggle All</span>
    </label>
  </div>
  
  <div class='checkbox toggleAll' data-role='toggle' data-classgroup='2ndrow'>
    <label>
      <input type='checkbox' value='Toggle All' />
      <span>Toggle 2nd Row</span>
    </label>
  </div>
</div>
              
            
!

CSS

              
                $checkbox-success: #71BA51;
$checkbox-error: #EE543A;
$checkbox-default: #3c3c3c;
$checkbox-stroke-width: 3;
$checkbox-size: 24; // in pixels
$checkbox-fontsize: 18; // in pixels
$checkbox-fillmode: 1; // 1 = true / 0 = false
$checkbox-animationspeed: 1s;
$checkbox-wavesize: $checkbox-size;

body {
  background-color: #efefef;
  position: absolute;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  flex-direction: column;
}
.wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
  
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid #d3d3d3;
}
.checkbox {
  padding: 0.2rem 0.5rem;
  margin: 0;
  font-family: 'Verdana';
  font-size: #{$checkbox-fontsize}px;
  
  min-width: 220px;
  position: relative;
  
  &.no-label {
    min-width: auto;
    .field {
      padding-left: 0; 
    }
  }
  
  .hitbox {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: nowrap;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }
  
  .icon {
    position: relative;
    line-height: 0;
    
    .wave {
      position: absolute;
      z-index: 2;
      top: 50%;
      left: 50%;
      margin-top: #{0 - $checkbox-wavesize / 0.66}px;
      margin-left: #{0 - $checkbox-wavesize / 0.66}px;
      width: #{$checkbox-wavesize * 3}px;
      height: #{$checkbox-wavesize * 3}px;
      border-radius: 50%;
      background-color: rgba($checkbox-success,0.5);
      opacity: 0;
      transform: scale(0);
    }
    &:before {
      content: '';
      display: block;
      position: absolute;
      z-index: 1;
      top: 50%;
      left: 50%;
      margin-top: #{0 - $checkbox-wavesize / 0.66}px;
      margin-left: #{0 - $checkbox-wavesize / 0.66}px;
      width: #{$checkbox-wavesize * 3}px;
      height: #{$checkbox-wavesize * 3}px;
      border-radius: 50%;
      background-color: rgba($checkbox-default,0.05);
      opacity: 0;
      transform: scale(0);
      transition: 0.15s ease-in-out;
    }
    
    &:hover {
      &:before {
        opacity: 1;
        transform: scale(0.8);
      }
    }
  }
  
  svg {
    width: #{$checkbox-size}px;
    height: #{$checkbox-size}px;
    position: relative;
    z-index: 3;
    path {
      stroke-width: $checkbox-stroke-width;
    }
  }
  
  .sign {
    stroke: $checkbox-default;
    stroke-dasharray: 108;
    stroke-dashoffset: 108;
  }
  
  .blank {
    stroke: $checkbox-default;
    transform-origin: center center;
    transition: 0.5s ease-in-out;
    fill: #fff;
  }
  
  .hidden-input {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    visibility: hidden;
    width: 0;
    height: 0;
  }
  
  .field {
    padding-left: 0.5rem; 
    .label {
      color: $checkbox-default;
      font-weight: 500;
      font-size: 1em;
      line-height: 1.1;
    }
  }
  
  &.checked {
    .sign {
      animation: checkbox-animatesign $checkbox-animationspeed ease-in-out normal 1 both;
    }
    .blank {
      animation: checkbox-animateblank $checkbox-animationspeed ease-in-out 1 both;
      stroke: $checkbox-success;
    }
    .icon .wave {
      animation: checkbox-animatewave 0.5s ease-in-out 1 both;
    }
  }
  
  &.unchecked {
    .sign {
      animation: checkbox-animatesign $checkbox-animationspeed ease-in-out reverse 1 both;
    }
    .blank {
      animation: checkbox-animateblank $checkbox-animationspeed ease-in-out 1 both;
      stroke: $checkbox-success;
    }
  }
}

@keyframes checkbox-animateblank {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  20% {
    transform: scale(0) rotate(45deg);
    opacity: 0;
  }
  90% {
    transform: scale(0.5);
    opacity: 0;
    @if ($checkbox-fillmode==1) {
      fill: $checkbox-success;
    }
  }
  95% {
    transform: scale(1.1);
    opacity: 1;
    @if ($checkbox-fillmode==1) {
      fill: $checkbox-success;
    }
  }
  100% {
    transform: scale(1);
    opacity: 1;
    @if ($checkbox-fillmode==1) {
      fill: $checkbox-success;
    }
  }
}

@keyframes checkbox-showblank {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  10% {
    transform: scale(0.4);
    opacity: 0;
  }
  80% {
    transform: scale(0.4);
    opacity: 0;
  }
  90% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes checkbox-animatesign {
  0% {
    stroke: $checkbox-default;
    stroke-dasharray: 108;
    stroke-dashoffset: 108;
  }
  75% {
    stroke: $checkbox-default;
    stroke-dasharray: 110;
    stroke-dashoffset: -90;
  }
  100% {
    stroke: $checkbox-success;
    stroke-dasharray: 110;
    stroke-dashoffset: -90;
    @if ($checkbox-fillmode==1) {
      stroke: #fff;
    }
  }
}

@keyframes checkbox-animatewave {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  
  25% {
    opacity: 1;
    transform: scale(0.5);
  }
  
  50% {
    opacity: 0;
    transform: scale(1);
  }
  
  100% {
    opacity: 0;
    transform: scale(0);
  }
}

.initCheckbox {
  background-color: $checkbox-success;
  border: none;
  padding: 1rem 1.5rem;
  cursor: pointer;
  span {
    color: #fff;
    font-size: 1.2rem;
    line-height: 1.2;
  }
  
  &[disabled] {
    opacity: 0.5;
  }
}
              
            
!

JS

              
                $.fn.checkboxify = function(options) {
  
  var selector = $(this).getSelector(true)
  var groupObj = new Object()

  function checkboxGroupCheck(ignoreToggler) {
    if (ignoreToggler == null) {
      ignoreToggler = false
    }
    for (var key in groupObj) {
      groupObj[key]['count'] = $('.'+key+':not([data-role="toggle"]) input.hidden-input:checked').length
      var $goToggler = $(selector+'[data-role="toggle"][data-classgroup="'+key+'"]')
      var $goTogglerInput = $(selector+'[data-role="toggle"][data-classgroup="'+key+'"] input.hidden-input')
      if (groupObj[key]['count'] == groupObj[key]['total']) {
        if (!ignoreToggler) $goToggler.addClass('checked')
      } else {
        if (!ignoreToggler) $goToggler.removeClass('checked')
      }
      if (!ignoreToggler) $goTogglerInput.prop('checked', groupObj[key]['count'] == groupObj[key]['total'] ? true : false)
    }
  }
  
  $(selector).each(function(i,e) {
    var $this = $(this)
    var $cb = $(e)
    var hasLabel = !$cb.hasClass('no-label')
    var label = hasLabel ? $cb.find('label').text() : null
    var input = $cb.find('input[type="checkbox"]')
    var isChecked = input.prop('checked')
    var value = input.prop('value')
      
    // check if data attributes are available
    var isToggler = $cb.data('role') == 'toggle' ? true : false
    
    // set group object
    if (isToggler) {
      if (Object.keys(groupObj).indexOf($cb.data('classgroup')) == -1) {
        groupObj[$cb.data('classgroup')] = {}
        groupObj[$cb.data('classgroup')]['total'] = $(selector + '.' + $cb.data('classgroup') + ':not([data-role="toggle"])').length
        groupObj[$cb.data('classgroup')]['count'] = 0
      }
    }

    // create checkbox markup
    var el01 = '<label class="hitbox"><div class="icon"><svg x="0px" y="0px" width="30px" height="30px" viewBox="0 0 30 30" xml:space="preserve"><path class="blank" fill="none" stroke="#000000" stroke-width="1" stroke-miterlimit="10" d="M27,23.444 C27,25.408,25.408,27,23.444,27H6.556C4.592,27,3,25.408,3,23.444V6.556C3,4.592,4.592,3,6.556,3h16.889C25.408,3,27,4.592,27,6.556 V23.444z"/> <path class="sign" fill="none" stroke="#000000" stroke-width="1" stroke-miterlimit="10" d="M27,14v9.444 C27,25.408,25.408,27,23.444,27H6.556C4.592,27,3,25.408,3,23.444V6.556C3,4.592,4.592,3,6.556,3h16.889C25.408,3,27,4.592,27,6.556 v1.516C18.929,8.429,13.125,18.75,13.125,18.75L9.5,14"/></svg><div class="wave"></div></div><div class="field">'
    el01 += hasLabel ? '<div class="label">'+label+'</div>' : ''
    el01 += '<input class="hidden-input" type="checkbox" value="'+value+'" '
    el01 += isChecked ? 'checked="checked"' : ''
    el01 += '/></div></label>'
    $cb.html(el01)

    // on change event
    var cbInput = $cb.find('input.hidden-input')
    $cb.addClass(cbInput[0].checked ? 'checked' : '')
    cbInput.on('change', function(el){
      $cbInput = $(this)
      $cbWrapper = $cbInput.closest('.checkbox')
      $cbWrapper.toggleClass('checked')
      
      if (isToggler) {
        var toggleGroup = $cbWrapper.data('classgroup')
        if ($cbInput[0].checked) {
          $('.'+toggleGroup+':not([data-role="toggle"])').addClass('checked')
        } else {
          $('.'+toggleGroup+':not([data-role="toggle"])').removeClass('checked')
        }
        $('.'+toggleGroup+':not([data-role="toggle"]) input.hidden-input').prop('checked', $cbInput[0].checked)
      }
      checkboxGroupCheck()
      
      
    })
  })
  
  checkboxGroupCheck()

  return this
}

!function(e,t){var n=function(e){var n=[];for(;e&&e.tagName!==t;e=e.parentNode){if(e.className){var r=e.className.split(" ");for(var i in r){if(r.hasOwnProperty(i)&&r[i]){n.unshift(r[i]);n.unshift(".")}}}if(e.id&&!/\s/.test(e.id)){n.unshift(e.id);n.unshift("#")}n.unshift(e.tagName);n.unshift(" > ")}return n.slice(1).join("")};e.fn.getSelector=function(t){if(true===t){return n(this[0])}else{return e.map(this,function(e){return n(e)})}}}(window.jQuery)


$(document).ready(function(){
  $('.initCheckbox').on('click',function(){
    $('.checkbox').checkboxify()
    $(this).prop('disabled', true)
  })
})
              
            
!
999px

Console