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

              
                <div class="block-charts">

  <div class="block-chart transport">

    <h1 class="block-chart__title">Transportation of the East Bay</h1>

    <div class="block-chart__wrapper" aria-hidden="true">

      <div class="block-chart__bar bicycle">
        <div class="block-chart__label">Bicycle</div>
        <div class="block-chart__track">
          <div class="block-chart__progress">
            <span class="block-chart__percentage"></span>
          </div>
        </div>
      </div>

      <div class="block-chart__bar walking">
        <div class="block-chart__label">Walking</div>
        <div class="block-chart__track">
          <div class="block-chart__progress">
            <span class="block-chart__percentage"></span>
          </div>
        </div>
      </div>

      <div class="block-chart__bar bus">
        <div class="block-chart__label">Bus</div>
        <div class="block-chart__track">
          <div class="block-chart__progress">
            <span class="block-chart__percentage"></span>
          </div>
        </div>
      </div>

      <div class="block-chart__bar motorcycle">
        <div class="block-chart__label">Motorcycle</div>
        <div class="block-chart__track">
          <div class="block-chart__progress">
            <span class="block-chart__percentage"></span>
          </div>
        </div>
      </div>

      <div class="block-chart__bar skateboard">
        <div class="block-chart__label">Skateboard</div>
        <div class="block-chart__track">
          <div class="block-chart__progress">
            <span class="block-chart__percentage"></span>
          </div>
        </div>
      </div>

      <div class="block-chart__bar roller-skates">
        <div class="block-chart__label">Roller Skates</div>
        <div class="block-chart__track">
          <div class="block-chart__progress">
            <span class="block-chart__percentage"></span>
          </div>
        </div>
      </div>

      <div class="block-chart__bar car">
        <div class="block-chart__label">Car</div>
        <div class="block-chart__track">
          <div class="block-chart__progress">
            <span class="block-chart__percentage"></span>
          </div>
        </div>
      </div>

    </div>

    <table class="block-chart__table visually-hidden">
      <caption>East Bay Transportation</caption>
      <tr>
        <th scope="col">Transportation Type</th>
        <th scope="col">Overall</th>
        <th scope="col">Berkeley</th>
        <th scope="col">Emeryville</th>
        <th scope="col">Oakland</th>
        <th scope="col">Richmond</th>
      </tr>
      <tr>
        <th scope="row">Bicycle</th>
        <td>33.6%</td>
        <td>35.7%</td>
        <td>27.3%</td>
        <td>20.8%</td>
        <td>18.7%</td>
      </tr>
      <tr>
        <th scope="row">Walking</th>
        <td>3.9%</td>
        <td>4.0%</td>
        <td>5.0%</td>
        <td>2.8%</td>
        <td>0.8%</td>
      </tr>
      <tr>
        <th scope="row">Bus</th>
        <td>8.4%</td>
        <td>8.7%</td>
        <td>9.3%</td>
        <td>4.3%</td>
        <td>2.4%</td>
      </tr>
      <tr>
        <th scope="row">Motorcycle</th>
        <td>2.1%</td>
        <td>2.4%</td>
        <td>1.0%</td>
        <td>0.9%</td>
        <td>0.0%</td>
      </tr>
      <tr>
        <th scope="row">Skateboard</th>
        <td>0.3%</td>
        <td>0.3%</td>
        <td>0.2%</td>
        <td>0.1%</td>
        <td>0.0%</td>
      </tr>
      <tr>
        <th scope="row">Roller Skates</th>
        <td>0.6%</td>
        <td>0.7%</td>
        <td>0.7%</td>
        <td>0.1%</td>
        <td>0.0%</td>
      </tr>
      <tr>
        <th scope="row">Car</th>
        <td>51.0%</td>
        <td>48.1%</td>
        <td>56.5%</td>
        <td>71.1%</td>
        <td>76.4%</td>
      </tr>
    </table>

    <p class="block-chart__population">Total population: <span class="block-chart__number">13,797</span></p>

    <div class="block-chart__buttons" aria-hidden="true">

      <button class="button selected" id="transport-overall">Overall</button>
      <button class="button" id="transport-berkeley">Berkeley</button>
      <button class="button" id="transport-emeryville">Emeryville</button>
      <button class="button" id="transport-oakland">Oakland</button>
      <button class="button" id="transport-richmond">Richmond</button>

    </div>

  </div>

</div>
              
            
!

CSS

              
                /* Typography */
html {
  font-size: 62.5%;
  font-family: 'Muli', sans-serif;
}

body {
  font-size: 1.8rem;
  background: #fefefe;
}

h1 {
  font-weight: 700;
  font-size: 2.4rem;
  margin-bottom: 3rem;
}

/* To create content just for screen readers (https://developer.paciellogroup.com/blog/2012/05/html5-accessibility-chops-hidden-and-aria-hidden/) */
.visually-hidden {
  clip-path: inset(100%);
  clip: rect(1px 1px 1px 1px); /* IE 6/7 */
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap; /* added line */
  width: 1px;
}

/* Charts Block */
.block-chart {
  
  text-align: center;
  
  &__bar {
    display: flex;
    align-items: center;
    padding-bottom: 2%;
    padding-right: 28px;
  }

  &__label {
    flex: 0 1 auto;
    width: 30%;
    font-size: 1.6rem;
    min-width: 170px;
    margin-right: 3%;

    text-transform: uppercase;
    text-align: right;
    letter-spacing: 1px;
  }

  &__track {
    flex: 1 1 auto;
  }

  &__progress {
    overflow: visible !important;
    height: 35px;
    width: 0;
    border-radius: 6px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    background-color: #000;
    position: relative;
  }

  &__percentage {
    width: 40px;
    line-height: 35px;
    text-align: left;
    font-size: 1.4rem;
    position: absolute;
    top: 0;
    right: -50px;

    &:after {
      content: "%";
    }
  }

  &__population {
    margin-bottom: 0;

    color: #000;
    text-align: center;
  }
  
  &__buttons {
    
    padding-top: 3rem;
    
    button {
      background: transparent;
      border: 0;
      font-size: 1.8rem;
      line-height: 2;
      font-family: 'Muli', sans-serif;
      font-weight: normal;

      margin: 0 0.5em 1em;

      &:hover,
      &.selected {
        color: lighten(black, 10%);
        border-bottom: 1px solid black;
      }
    }
  }
}

              
            
!

JS

              
                /* jQuery Assignment */
window.jQuery = window.$ = jQuery;

/* Toggle Button Classes */
$(".block-chart__buttons .button").each(function() {
  $(this).click(function() {
    $(this)
      .siblings(".selected")
      .removeClass("selected");
    $(this).addClass("selected");
  });
});

/* Participant Populations */
var populationData = [13797, 11362, 1143, 1169, 123];

/* Update Population Function */
updatePopulation = function(populationIndex) {
  
  $(".transport .block-chart__population").each(function() {
    
    var number = $(this).find(".block-chart__number");
    currentPopulation = number.text().replace(/,/g, "");
    newPopulation = populationData[populationIndex];
    
    /* Set new population */
    $(number).text(newPopulation);
    $(number).each(function() {
      
      /* Count Up Number */
      var countUpPopulation = new CountUp(
        this,
        currentPopulation,
        newPopulation,
        0,
        0.8
      );
      
      countUpPopulation.start();
      
    });
  });
};

/* Transport Chart + Data */
var transportDatasetOverall = [33.6, 3.9, 8.4, 2.1, 0.3, 0.8, 51.0];
    transportDatasetBerkeley = [35.7, 4.0, 8.7, 2.4, 0.3, 0.7, 48.1];
    transportDatasetEmeryville = [27.3, 5.0, 9.3, 1.0, 0.2, 0.7, 56.5];
    transportDatasetOakland = [20.8, 2.8, 4.3, 0.9, 0.1, 0.1, 71.1];
    transportDatasetRichmond = [18.7, 0.8, 2.4, 0.0, 0.0, 0.0, 76.4];

/* Load Chart Data Function */
updateChart = function(dataset) {
  
  $(".block-chart__bar").each(function(index) {
    
    var element = $(this).find(".block-chart__percentage");
    currentNumber = element.text().replace(/,/g, "");
    newNumber = dataset[index];
    
    /* Set Number */
    $(element).text(newNumber);
    $(element).each(function() {
      
      /* Count Up Number */
      var countUp = new CountUp(this, currentNumber, newNumber, 1, 0.8);
      countUp.start();
    });
    /* Animate Bar */
    $(this)
      .find(".block-chart__progress")
      .stop()
      .animate(
        { width: dataset[index] + "%" },
        600,
        "swing"
      );
  });
};

/* Load Overall Data First */
updateChart(transportDatasetOverall);
updatePopulation(0);

/* Buttons to Load New Data */
$("#transport-overall").click(function() {
  updateChart(transportDatasetOverall);
  updatePopulation(0);
});

$("#transport-berkeley").click(function() {
  updateChart(transportDatasetBerkeley);
  updatePopulation(1);
});

$("#transport-emeryville").click(function() {
  updateChart(transportDatasetEmeryville);
  updatePopulation(2);
});

$("#transport-oakland").click(function() {
  updateChart(transportDatasetOakland);
  updatePopulation(3);
});

$("#transport-richmond").click(function() {
  updateChart(transportDatasetRichmond);
  updatePopulation(4);
});

              
            
!
999px

Console