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.

            
              <article>
  <section>
    <h1>Intro: Salads That Sizzle</h1>
    <p>I have two young, very active boys, so summer means spending our days outside in the yard and cooking our meals on the grill as often as possible. We grill everything—including salads, which are a delicious surprise. A quick turn on the grill gives salad greens caramelized edges, while their interior leaves remain crisp-tender. Their flavor gets concentrated and infused with smokiness, making for salads that are complex and satisfying. For summer dinner parties they’re ideal—unexpected, visually appealing, and tasty—but they’re also easy enough for weeknights.</p>
  </section>
  <section>
    <h1>Step One: Start With Hearty Greens</h1>
    <p>Making a great grilled salad begins with choosing the right greens. Delicate ones like arugula, watercress, or mizuna don’t work. Instead, you need greens with thick leaves that won’t wilt too quickly, turn slimy, or burn to a crisp. You should also use greens with a sturdy core, so you can cut a head into halves or wedges and have the leaves stay together on the grill.</p>
  </section>
  <section>
    <h1>Step Two: Bring on the Romaine</h1>
    <p>Substantial and slightly bitter greens in the romaine and chicory families are perfect for the grill. I like to pair them with bright, tangy dressings, like a lemony Caesar or a summery fines herbes salsa verde. Another of my favorites to grill is iceberg lettuce because it forms such sturdy, attractive wedges. As a milder lettuce, it benefits from stronger flavors like bacon and blue cheese, which make for a great update on the classic steakhouse iceberg wedge salad. These three salads work because they’re simple, with just enough bold flavors to highlight the delicious smokiness of the grilled greens.</p>
  </section>
  <section>
    <h1>Step Three: Grill Fast and Hot</h1>
    <p>Once you’ve settled on what to grill, the how to grill part is pretty straightforward. Place the greens over medium-hot direct heat and leave them alone just long enough for them to develop grill marks. Be sure your fire is the right temperature: too hot and the greens will burn; not hot enough and they will wilt and become slimy.</p>
  </section>
  <section>
    <h1>Conclusion: More Tips</h1>
    <p>There are a few more things to keep in mind when grilling greens. They absorb other flavors very easily, so always clean the grill grate well or your salad may end up tasting like what you grilled the day before. If you’re using charcoal, avoid lighter fluid and lighter-fluid-infused charcoal briquettes, which can impart a chemical taste. It’s also important to have your dressing and toppings prepared before you put the greens on the grill—these salads are best served immediately, and they can be ready faster than it takes the family to come in from the yard.</p>
  </section>
</article>
<footer>
  <div class="vcent"></div>
  <div class="container">
    <p>Brought to you by <a href="http://rileyjshaw.com" target="_blank">rileyjshaw</a> with heavy inspiration from <a href="http://slinky.iclanzan.com/" target="_blank">slinky.js</a>. Recipe from <a href="http://www.finecooking.com/articles/salads-that-sizzle.aspx" target="_blank">finecooking.com</a>.</p>
  </div>
</footer>

            
          
!
            
              $sectionWidth: 480px

html, body, .vcent
  height: 100%
  
body
  margin: 0
  font-family: 'PT Serif', serif
  color: #333
  -webkit-font-smoothing: antialiased
  -moz-osx-font-smoothing: grayscale

article
  position: relative
    
section
  width: $sectionWidth
  margin: 0 auto
  overflow: hidden
  
  h1
    position: relative
    height: 42px
    width: $sectionWidth
    box-sizing: border-box
    margin: 0
    padding-left: 1em
    font: 16px/42px 'PT Sans', sans-serif
    background: skyblue
    cursor: pointer

    .progress
      position: absolute
      top: 0
      bottom: 0
      left: 0
      background: rgba(255, 255, 255, .2)

    .text
      position: relative

  p
    margin-left: 18px
    margin-right: 18px
    line-height: 1.46em
    font-size: 16px
    text-align: justify

footer
  position: relative
  height: 100%
  width: 100%
  text-align: center
  font-size: 36px
  color: #eee
  background: #333
  
  a
    color: #eee
    
.vcent, .container
  vertical-align: middle
  display: inline-block
    
.container
  width: 60%
  text-align: justified
    
            
          
!
            
              !function () {
  function getTop (element) {
    var top = 0;
    do {
      top += element.offsetTop  || 0;
      element = element.offsetParent;
    } while(element);

    return top;
  }

  function smoothScroll (top) {
    var windowTop = window.pageYOffset;
    if (top !== windowTop) {
      var direction = top - windowTop > 0 ? 1 : -1;
      function scroll () {
        var diff = (top - windowTop) * direction;
        if (diff > 0) {
          windowTop += Math.min(diff, 30) * direction;
          window.scrollTo(0, windowTop);
          window.requestAnimationFrame(scroll);
        }
      }
      window.requestAnimationFrame(scroll);
    }
  }
  
  function initSections (section, i) {
    if (section.el) {
      section.top = getTop(section.el);
      section.height = section.el.offsetHeight;
      section.header.onclick = function () { smoothScroll(section.top - topLatch); };
      section.fixed = false;
      section.el.style.cssText = section.header.style.cssText = '';
      return section;
    }

    var h1 = section.querySelector('h1');
    var progress;
    var height = section.offsetHeight;
    var topLatch = i * 42;
    var top = getTop(section);
    
    h1.innerHTML = '<span class="progress"></span><span class="text">' + h1.textContent + '</span>';
    progress = h1.querySelector('.progress');
    // todo: messy, but easy to override
    h1.onclick = function () { smoothScroll(top - topLatch); };
    
    return {
      el: section,
      header: h1,
      progress: progress,
      top: top,
      height: height,
      topLatch: topLatch,
      bottomLatch: (sections.length - 1 - i) * 42,
      fixed: false
    };
  }
  
  function scrollHandlerInner (section, top) {
    var diff = top - section.top;
    var progressStyle = section.progress.style;
    var progressStyleWidth = progressStyle.width;
    if (diff >= -section.topLatch) {
      if (diff < section.height) {
        progressStyle.width = Math.min((diff + section.topLatch) / (section.height - 42), 1) * 100 + '%';
      } else if (progressStyleWidth !== '100%') progressStyle.width = '100%';
      if (section.fixed !== 'top') {
        section.fixed = 'top';
        section.header.style.cssText = 'position:fixed;top:' + section.topLatch + 'px';
        section.el.style.cssText = 'padding-top: 42px';
      }
    } else {
      if (progressStyleWidth !== '0px') progressStyle.width = 0;
      if (diff + windowHeight - section.bottomLatch - 42 < 0) {
        if (section.fixed !== 'bottom') {
          section.fixed = 'bottom';
          section.header.style.cssText = 'position: fixed;bottom:' + section.bottomLatch + 'px';
          section.el.style.cssText = 'padding-bottom: 42px';
        }
      } else if (section.fixed) {
        section.fixed = false;
        section.el.style.cssText = section.header.style.cssText = '';
      }
    }
  }

  function stickToBottom (section) {
    section.fixed = false;
    section.header.style.cssText = 'position: absolute;bottom:' + section.bottomLatch + 'px';
    section.progress.style.width = '100%';
  }

  function scrollHandler () {
    var top = window.pageYOffset;
    // todo handle scrolling past top
    if (articleBottom - top < compressedHeight) {
      if (!stickyLatch) {
        stickyLatch = 'bottom';
        sections.forEach(stickToBottom);
      }
    } else {
      if (stickyLatch) stickyLatch = false;
      sections.forEach(function (section) {
        scrollHandlerInner(section, top);
      });
    }
  }

  function initGlobal () {
    windowHeight = window.innerHeight;
    articleTop = getTop(article);
    sections = sections.map(initSections);
    stickyLatch = false;
    scrollHandler();
    articleBottom = articleTop + article.offsetHeight;
  }
  
  var article = document.querySelector('article');
  var sections = Array.prototype.slice.call(article.querySelectorAll('section'), 0);
  var compressedHeight = sections.length * 42;
  var windowHeight, articleTop, articleBottom, sections, stickyLatch, resizeDone;

  initGlobal();

  window.addEventListener('scroll', scrollHandler, false);
  window.addEventListener('resize', function () {
    clearTimeout(resizeDone);
    resizeDone = setTimeout(initGlobal, 500);
  }, 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