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 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

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

              
                %section.hero
  .hero_inner
    .hero_inner__brand
      %img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/barslogo.png'}
      .logo_bars
        .one
        .two
        .three
        .four
        .five
    .hero_inner_sub
      %h2 Bars, bars everywhere!
      %h3 A simple, easy to use javascript plugin for making statistical bars. Oh, they're responsive too!
      %h4 Compatible with Chrome, FF, Opera, Safari, IE 10+
      .love Created by <a href="https://twitter.com/jamiecoulter89" target ="_blank">Jamie Coulter</a>
    .hero_inner_cta
      %a.b{:href => 'https://www.jamiecoulter.co.uk/dev/bars.zip'} Get Bars.js
      %a.b.scroll{:href => '#'} Examples
%section.bar.top
  %h2 Bar styles
  %h3 Pre-built bar themes, more to come soon!
  %section.wrap
    .wrap_left
      .bar_description
        %h4 Thin Bars
        %p .bar_group__bar.thin
    .wrap_right
      .bar_group
        .bar_group__bar.thin{:value => '230'}
        .bar_group__bar.thin{:value => '130'}
        .bar_group__bar.thin{:value => '160'}
        .bar_group__bar.thin{:value => '340'}
        .bar_group__bar.thin{:value => '290'}
    .clear
  %section.wrap
    .wrap_left
      .bar_description
        %h4 Thick Bars
        %p .bar_group__bar.thick
    .wrap_right
      .bar_group
        .bar_group__bar.thick{:value => '230'}
        .bar_group__bar.thick{:value => '130'}
        .bar_group__bar.thick{:value => '160'}
        .bar_group__bar.thick{:value => '340'}
        .bar_group__bar.thick{:value => '290'}
    .clear
  %section.wrap
    .wrap_left
      .bar_description
        %h4 Bars with no background
        %p .bar_group__bar.n_bg
    .wrap_right
      .bar_group
        .bar_group__bar.thin.n_bg{:value => '230'}
        .bar_group__bar.thin.n_bg{:value => '130'}
        .bar_group__bar.thin.n_bg{:value => '160'}
        .bar_group__bar.thin.n_bg{:value => '340'}
        .bar_group__bar.thin.n_bg{:value => '290'}
    .clear
%section.alt
  %section.bar
    %h2 Value options
    %h3 Setting maximum values
    %section.wrap
      .wrap_left
        .bar_description
          %h4 Default max
          %p By default, Bars.js finds the highest value in a bar group and bases the comparison on that
      .wrap_right
        .bar_group
          .bar_group__bar.thin{:value => '230'}
          .bar_group__bar.thin{:value => '130'}
          .bar_group__bar.thin{:value => '160'}
          .bar_group__bar.thin{:value => '340'}
          .bar_group__bar.thin{:value => '290'}
    .clear
    %section.wrap
      .wrap_left
        .bar_description
          %h4 Defined max of 500
          %p If you want to change the maximum of the bar the group add {:max => 'Your max'} to the bar group element
      .wrap_right
        .bar_group{:max => '500'}
          .bar_group__bar.thin{:value => '230'}
          .bar_group__bar.thin{:value => '130'}
          .bar_group__bar.thin{:value => '160'}
          .bar_group__bar.thin{:value => '340'}
          .bar_group__bar.thin{:value => '290'}
    .clear
%section.bar
  %h2 Display option
  %h3 Show max/min values, tooltips and more.
  %section.wrap
    .wrap_left
      .bar_description
        %h4 Show data labels
        %p :label => 'Hunger'
    .wrap_right
      .bar_group
        .bar_group__bar.thin{:value => '230',:label => 'Oranges'}
        .bar_group__bar.thin{:value => '130',:label => 'Apples'}
        .bar_group__bar.thin{:value => '160',:label => 'Grapes'}
        .bar_group__bar.thin{:value => '340',:label => 'Strawberrys'}
        .bar_group__bar.thin{:value => '290',:label => 'Pineapples'}
    .clear
  %section.wrap
    .wrap_left
      .bar_description
        %h4 Show values
        %p :show_values => 'true'
    .wrap_right
      .bar_group
        .bar_group__bar.thin{:value => '343',:label => 'jQuery',:show_values => 'true'}
        .bar_group__bar.thin{:value => '235',:label => 'AJAX',:show_values => 'true'}
        .bar_group__bar.thin{:value => '675',:label => 'PHP',:show_values => 'true'}
        .bar_group__bar.thin{:value => '456',:label => 'SASS',:show_values => 'true'}
        .bar_group__bar.thin{:value => '245',:label => 'HAML',:show_values => 'true'}
    .clear
  %section.wrap
    .wrap_left
      .bar_description
        %h4 Custom unit of measure
        %p :unit => '% etc'
    .wrap_right
      .bar_group
        .bar_group__bar.thin{:value => '343',:label => 'Vuaxhall Corsa',:show_values => 'true',:unit => 'mpg'}
        .bar_group__bar.thin{:value => '235',:label => 'Toyota Celica',:show_values => 'true',:unit => 'mpg'}
        .bar_group__bar.thin{:value => '675',:label => 'Landrover',:show_values => 'true',:unit => 'mpg'}
        .bar_group__bar.thin{:value => '456',:label => 'Peagueot 106',:show_values => 'true',:unit => 'mpg'}
        .bar_group__bar.thin{:value => '245',:label => 'Lawnmower',:show_values => 'true',:unit => 'mpg'}
    .clear
  %section.wrap
    .wrap_left
      .bar_description
        %h4 Show tooltips
        %p :tooltip => 'true'
    .wrap_right
      .bar_group
        .bar_group__bar.thin{:value => '343',:label => 'jQuery',:show_values => 'true',:tooltip => 'true'}
        .bar_group__bar.thin{:value => '235',:label => 'AJAX',:show_values => 'true',:tooltip => 'true'}
        .bar_group__bar.thin{:value => '675',:label => 'PHP',:show_values => 'true',:tooltip => 'true'}
        .bar_group__bar.thin{:value => '456',:label => 'SASS',:show_values => 'true',:tooltip => 'true'}
        .bar_group__bar.thin{:value => '245',:label => 'HAML',:show_values => 'true',:tooltip => 'true'}
    .clear
%section.alt
  %section.bar
    %h2 Colors
    %h3 Setting color schemes
    %section.wrap
      .wrap_left
        .bar_description
          %h4 Gradient bars
          %p .bar_group__bar.thin.gradient
      .wrap_right
        .bar_group
          .bar_group__bar.thin.gradient{:value => '230'}
          .bar_group__bar.thin.gradient{:value => '130'}
          .bar_group__bar.thin.gradient{:value => '160'}
          .bar_group__bar.thin.gradient{:value => '340'}
          .bar_group__bar.thin.gradient{:value => '290'}
    .clear
    %section.wrap
      .wrap_left
        .bar_description
          %h4 Custom colors
          %p Assign a new css selector
      .wrap_right
        .bar_group{:max => '500'}
          .bar_group__bar.thin.c_red{:value => '230'}
          .bar_group__bar.thin.c_green{:value => '130'}
          .bar_group__bar.thin.c_blue{:value => '160'}
          .bar_group__bar.thin.c_pink{:value => '340'}
          .bar_group__bar.thin.c_brown{:value => '290'}
    .clear
%section.bar
  %h2 Effects
  %h3 Snazzy effects for extra swag
  %section.wrap
    .wrap_left
      .bar_description
        %h4 Elastic
        %p .elastic
    .wrap_right
      .bar_group{:max => '600'}
        .bar_group__bar.thin.elastic{:value => '230',:label => 'Oranges'}
        .bar_group__bar.thin.elastic{:value => '130',:label => 'Apples'}
        .bar_group__bar.thin.elastic{:value => '160',:label => 'Grapes'}
        .bar_group__bar.thin.elastic{:value => '340',:label => 'Strawberrys'}
        .bar_group__bar.thin.elastic{:value => '290',:label => 'Pineapples'}
    .clear
              
            
!

CSS

              
                // ============================================================== 
// Global Options
// ==============================================================

$bar-transition-time:1s;

// ============================================================== 
// Mixins
// ==============================================================

@mixin color($id){
  background:adjust-hue(#E66E25,$id * 10%);
}

// ============================================================== 
// Bar style options
// ==============================================================

// Thin bar options

$thin-outer-width: 100%;
$thin-outer-height: 4px;
$thin-outer-radius: $thin-outer-height/2;
$thin-outer-color: #E4E4E4;
$thin-inner-width: 0%;
$thin-inner-height: $thin-outer-height;
$thin-inner-radius: $thin-outer-radius;
$thin-inner-color: red;
$thin-group-spacing:10px;

// Thick bar options

$thick-outer-width: 100%;
$thick-outer-height: 12px;
$thick-outer-radius: $thick-outer-height/2;
$thick-outer-color: #E4E4E4;
$thick-inner-width: 0%;
$thick-inner-height: $thick-outer-height;
$thick-inner-radius: $thick-outer-radius;
$thick-inner-color: red;
$thick-group-spacing:10px;

// ============================================================== 
// Placeholders
// ==============================================================

%outer{
  display:block;
  content:'';
  position:absolute;
  z-index:-1;
}

// Thin bar

%thin_bar--outer{
  @extend %outer;
  width:$thin-outer-width;
  height:$thin-outer-height;
  border-radius:$thin-outer-radius;
  background:$thin-outer-color;
}

%thin_bar--inner{
  width:$thin-inner-width;
  height:$thin-inner-height;
  border-radius:$thin-inner-radius;
  background:$thin-inner-color;
  margin-bottom:$thin-group-spacing;
  transition:width $bar-transition-time;
}

// Thick bar

%thick_bar--outer{
  @extend %outer;
  width:$thick-outer-width;
  height:$thick-outer-height;
  border-radius:$thick-outer-radius;
  background:$thick-outer-color;
}

%thick_bar--inner{
  width:$thick-inner-width;
  height:$thick-inner-height;
  border-radius:$thick-inner-radius;
  background:$thick-inner-color;
  margin-bottom:$thick-group-spacing;
  transition:width $bar-transition-time;
}

// ============================================================== 
// Bars.js styles
// ==============================================================

body{

  // Data Styles
  .b_label{
    color:#929292;
    font-size:10px;
  }
  .bar_label_min,.bar_label_max{
    @extend .b_label;
  }
  .bar_label_max{
    position:absolute;
    right:0;
  }
  .bar_label_min{
    position:absolute;
    left:0;
  }
  .b_tooltip{
    transition:all $bar-transition-time;
    position:relative;
    float:left;
    left:100%;
    padding: 4px 10px 7px 10px;
    background-color: rgba(67, 66, 76, 0.81);
    transform:translateX(-50%) translateY(-30px);
    border-radius: 2px;
    line-height: 11px;
    span{
      @extend .b_label;
      color: white;
    }
  }
  .b_tooltip--tri{
    width: 0;
    height: 0;
    position: absolute;
    content: '';
    bottom: -5px;
    left: 0;
    right: 0;
    margin: auto;
    display: block;
    border-style: solid;
    border-width: 5px 5px 0 5px;
    border-color: rgba(67, 66, 76, 0.81) transparent transparent transparent;
  }

  // Bar colors
  @for $i from 1 through 100{
    .bar_group__bar:nth-of-type(#{$i}){
      @include color($i);
    }
  }

  .bar_group{
    position:relative;

    // Effects
    .elastic{
      background:#FF3357;
      transition-timing-function: cubic-bezier(0.500, 0.250, 0.375, 1.335);
      transition-duration:1s;
    }
    .gradient{
      &:after{
        content:'';
        display:block;
        background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(0, 0, 0, 0)), color-stop(100%, rgba(255, 255, 255, 0.39)));
        height:100%;
        width:100%;
        border-radius:100px;
      }
    }

    // Visual styles
    &__bar{
      &.n_bg{
        &:before{
          display:none !important;
        }
      }
      &.thin{
        @extend %thin_bar--inner;
        &::before{
          @extend %thin_bar--outer;
        }
      }
      &.thick{
        @extend %thick_bar--inner;
        &::before{
          @extend %thick_bar--outer;
        }
      }
      
    }
  }  
}

// ============================================================== 
// Page styles - Not part of Bars.js styles
// ==============================================================
// Responsive
// Responive breakpoints
$screen-xlarge: 1600px;
$screen-large: 1360px;
$screen-medium: 1024px;
$screen-small: 900px;
$screen-xsmall: 500px;
$screen-xxsmall: 530px;
$screen-xxxsmall: 263px;
// Responsive mixin
// @include when(width){styles}

@mixin when($width){
  @media screen and (max-width: $width) {
    @content
  }
}

body{
  margin:0;
  font-family:'montserrat';
  .clear{
    clear:both;
  }
  .bar{
    box-sizing:border-box;
    width:800px;
    margin:0 auto;
    @include when($screen-small){
      width:100%;
      padding:30px;
    }
    h2{
      font-size:28px;
      margin:60px 0px 3px 0px;
      color: #232531;
    }
    h3{
      font-size: 12px;
      color: #8092AB;
      margin: 0px 0px 60px 0px;
      font-weight: normal;
    }
    h4{
      font-size:18px;
      margin:0px 0px 3px 0px;
      color: #232531;
    }
  }

  // Custom colors
  .c_red{background:#E03E3E !important;}
  .c_green{background:#ADEA38 !important;}
  .c_blue{background:#6BAED6 !important;}
  .c_pink{background:#DC5C84 !important;}
  .c_brown{background:#824629 !important;}

  .wrap{
    position:relative;
    margin-bottom:50px;
    &_left{
      height:100%;
      border-right: 1px solid #e0e6ef;
      width: 300px;
      margin-right: 100px;
      margin-bottom:30px;
      float: left;position: absolute;
      @include when($screen-small){
        width:100%;
        position:relative;padding-bottom:30px;border-right: 0px solid #e0e6ef;border-bottom: 1px solid #e0e6ef;
      }
      p{
        font-size: 11px;
        color: #8092AB;
        margin: 11px 0px 0px 0px;
        font-weight: lighter;
        width: 80%;
        line-height: 17px;
      }
    }
    &_right{
      float:right;
      width:400px;
      position:relative;
      margin: 30px 0px;@include when($screen-small){
        width:100%;
      }
    }
  }
  .alt{
    background:#F7F7F7;
    padding:40px 0px;
    position:relative;
    z-index:-2;
  }
  .hero{
    background:#232531;
    padding:100px 50px;
    text-align:center;
    h2{
      color:white;
    }
    h3{
      color:#8E92AB;
      font-size:12px;
      font-weight:normal;
      margin-bottom:10px;
    }
    .love{
      font-size: 10px;
    color: rgb(142, 146, 171);
    margin: 60px 0px 60px 0px;
    }
    h4{
      font-size: 10px;
    color: #E2204B;
    margin: 10px;
    }
    
    a{
      color:#E2204B;
    }
    a.b{
      text-decoration:none;
      color:#8E92AB;
      font-size:12px;
      padding:12px 28px;
      margin:10px;
      border:2px solid #8E92AB;
      border-radius:30px;
      transition:all .3s;
      &:hover{
        color:white;
        border:2px solid white;
      }
    }
    &_inner{
      &__brand{
        img{
          @include when($screen-xxsmall){display:none;
        }
        } width:400px;
        position:relative;
        margin:0 auto 40px auto;
       
        .logo_bars{
          @include when($screen-xxsmall){
            position: relative;
    left: 0;
    bottom: 30px;
    width: 42px;
    margin: auto;
    right: 0;
          }
           position:absolute;
          left: 125px;
          bottom: 10px;
          %l_bar{
            height:0px;
            position:absolute;
            bottom:0;
            border-radius:20px;
            float:left;
            margin-right:10px;
            width:6px;
          }
          .one{
            @extend %l_bar;
            background:#E15525;
            animation:one .6s .4s forwards;
          }
          .two{
            @extend %l_bar;
            left:12px;
            animation:two .6s .6s forwards;
            background:#EDBF40;
          }
          .three{
            @extend %l_bar;
            left:24px;
            animation:three .6s .8s forwards;
            background:#85C557;
          }
          .four{
            @extend %l_bar;
            left:36px;
            background:#5EC5C5;
            animation:two .6s 1s forwards
          }
          .five{
            @extend %l_bar;
            left:48px;
            background:#7653A2;
            animation:one .6s 1.2s forwards
          }
        }
      }
    }
  }
}



// Logo animations
@keyframes one{
  from{height:0}
  to{height:20px;}
}
@keyframes two{
  from{height:0}
  to{height:36px;}
}
@keyframes three{
  from{height:0}
  to{height:56px;}
}
              
            
!

JS

              
                // Bars.js
// Author: Jamie Coulter
// Date: 13.10.15

// Globals

max_arr = {};

// ============================================================== 
// Assign each bar group a unique id
// ==============================================================

function bar_group(){
  group_ident = 1;
  $('.bar_group').each(function(){
    $(this).addClass('group_ident-' + group_ident);
    $(this).data('gid', group_ident);
    group_ident++;
  });
}

// ============================================================== 
// Determine the maximum value within a bar group
// ==============================================================

function get_max(){
  $('.bar_group').each(function(){
    var bgArr = [];
    $(this).children().each(function(){
      bgArr.push($(this).attr('value'));
    });
    max_arr['group_ident-' + $(this).data('gid')] = bgArr;
    if($(this).attr('max') !== undefined){
      $(this).data('bg_max',$(this).attr('max'));
    }else{
      $(this).data('bg_max',Math.max.apply(null, bgArr));
    }
  });
}

// ============================================================== 
// Data labels
// ==============================================================

function data_labels(){
  $('.bar_group__bar').each(function(){
    if($(this).attr('label') !== undefined){
      $('<p class="b_label">' + $(this).attr('label') + '</p>').insertBefore($(this));
    }
  });
}

// ============================================================== 
// Show values
// ==============================================================

function show_values(){
  $('.bar_group__bar').each(function(){
    if($(this).attr('show_values') == 'true'){
      $(this).css('margin-bottom','40px');
      if($(this).attr('unit') !== undefined){
        $(this).append('<p class="bar_label_min">0 ' + $(this).attr('unit') + '</p>');
      	$(this).append('<p class="bar_label_max">' + $(this).parent().data('bg_max') + ' ' + $(this).attr('unit') + '</p>');
      } else {
      	$(this).append('<p class="bar_label_min">0</p>');
      	$(this).append('<p class="bar_label_max">' + $(this).parent().data('bg_max') + '</p>');
      }
    }
  });
}

// ============================================================== 
// Show tooltips
// ==============================================================

function show_tooltips(){
  $('.bar_group__bar').each(function(){
    if($(this).attr('tooltip') == 'true'){
      $(this).css('margin-bottom','40px');
      $(this).append('<div class="b_tooltip"><span>' + $(this).attr('value') + '</span><div class="b_tooltip--tri"></div></div>');
    }
  });
}

// ============================================================== 
// Pop up when in view
// ==============================================================

function in_view(elem){
  var $elem = $(elem);
  var $window = $(window);
  var docViewTop = $window.scrollTop();
  var docViewBottom = docViewTop + $window.height();
  var elemTop = $elem.offset().top;
  var elemBottom = elemTop + $elem.height();
  if(docViewBottom > elemBottom - 45){
    $elem.css('width',(($elem.attr('value'))/($elem.parent().data('bg_max')) * 100) + '%');
  } 
}

// Fire if bars in view when page loads
$('.bar_group__bar').each(function(){
  in_view($(this));
});

// Check on window scroll
$(window).scroll(function(){
  $('.bar_group__bar').each(function(){
    in_view($(this));
  });
});

// ============================================================== 
// Init
// ==============================================================

function bars(){
	bar_group();
	get_max();
	data_labels();
	show_tooltips();
	show_values();	
}

bars(); // Start bars.js


// ============================================================== 
// Page stuff
// ==============================================================

$(".scroll").click(function() {
    $('html, body').animate({
        scrollTop: $(".top").offset().top - 34
    }, 600);
  return false;
});

              
            
!
999px

Console