css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <h1>Folding tutorial concept</h1>
<button id="toggle" class="fa-eye-slash"></button>

<div class="instructions">
  <h2>Self-invoking anonymous functions</h2>
  <p>Since we don't want to pollute the global namespace, we're going to encapsulate our demo within a self-invoking anonymous function. It starts like this:</p>
</div>
<div class="code">
  <pre><code class="language-javascript">;(function () {</code></pre>
</div>
<div class="instructions">
  <p>Note that we've added a <code class="language-javascript">;</code> at the beginning of the line. This is in case our file gets concatinated with something that didn't end with a semicolon.</p>
  <p>From here, we can include our function body. Let's write fizzbuzz.</p>
</div>
<div class="code">
  <pre><code class="language-javascript">    //fizzbuzz
    for (var i = 1; i <= 100; i++) {
        if (i % 15 === 0) {
            console.log('FizzBuzz');
        } else if (i % 3 === 0) {
            console.log('Fizz');
        } else if (i % 5 === 0) {
            console.log('Buzz');
        } else {
            console.log(i);
        }
    }</code></pre>
</div>
<div class="instructions">
  <p>This function prints 1 to 100 with "fizz" taking the place of any multiple of 3, "buzz" taking the place of any multiple of 5, and "fizzbuzz" taking the place of any multiple of both 3 and 5.</p>
  <p>Now that our function is defined, all we need to do is call it.</p>
</div>
<div class="code">
  <pre><code class="language-javascript">})();</code></pre>
</div>
<footer>
  <p>Demo brought to you by <a href="http://rileyjshaw.com" target="_blank">rileyjshaw</a>.</p>
</footer>
<script src=//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js></script>

            
          
!
            
              body
  overflow-y: scroll
  margin: 1.5em auto 0
  font: 27px 'Slabo 27px', serif
  color: #333
  
h1, .instructions, pre, footer
  width: 600px
  margin: auto

h1
  margin-bottom: .5em
    
h2
  margin-top: 0
  
h1, .instructions, footer
  max-width: 94%
    
.instructions
  overflow: hidden
  max-height: 400px
  transition: max-height 0.9s, opacity 0.3s 0.3s
  
  .instructions-hidden &
    max-height: 0
    opacity: 0
    transition: max-height 0.9s, opacity 0.3s

pre
  font-size: 24px
    
.code
  background: #002b36
  
#toggle
  position: fixed
  right: 12px
  bottom: 12px
  height: 48px
  width: 48px
  border: 0
  outline: 0
  font: 22px Fontawesome
  border-radius: 24px
  cursor: pointer
  color: #fff
  background: #ff6f00
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.3)

            
          
!
            
              function toggleClass (el, className) {
  if (el.classList) {
    el.classList.toggle(className);
  } else {
    var classes = el.className.split(' ');
    var existingIndex = classes.indexOf(className);

    if (existingIndex >= 0)
      classes.splice(existingIndex, 1);
    else
      classes.push(className);

    el.className = classes.join(' ');
  }
}

var body = document.body;
var toggle = document.getElementById('toggle');

hljs.initHighlightingOnLoad();
toggle.addEventListener('click', function () {
  toggleClass(body, 'instructions-hidden');
  toggleClass(toggle, 'fa-eye');
  toggleClass(toggle, 'fa-eye-slash');
}, false);

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console