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

              
                <body>


  
  <!--multiple full-screen panels that scroll up and down-->
  <!--note: using a-name elements so the links still work with js disabled-->
  <div id="mainStack">
    <div id="panel1" class="panel">
      <a name="1"></a>
      First panel
    </div>
    <div id="panel2" class="panel">
      <a name="2"></a>
      Second panel
    </div>
    <div id="panel3" class="panel">
      <a name="3"></a>
      Third panel
    </div>
    <div id="panel4" class="panel">
      <a name="4"></a>
      Fourth panel
    </div>
    <div id="panel5" class="panel">
      <a name="5"></a>
      Fifth panel
    </div>
    <div id="panel6" class="panel">
      <a name="6"></a>
      Sixth panel
    </div>
  </div>
  
</body>
              
            
!

CSS

              
                * {
  box-sizing: border-box; /* so we don't have to worry about padding affecting width */
}
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font: normal 16px/1.2 sans-serif;
}

#panel1, #panel2, #panel3, #panel4, #panel5, #panel6 {
  /* all of these are for demo only: */
  width: 100%;
  height: 100vh; /* css3 way to say 100% of the viewport height. works on IE9+ and modern browsers. needs patch for iOS devices: https://gist.github.com/pburtchaell/e702f441ba9b3f76f587. also needs patch for print stylesheets (height:auto). */
  text-align: center;
  font-size: 50px;
}
#panel1, #panel3, #panel5 {
  /* for demo only: */
  background-color: khaki;
}
#panel2, #panel4, #panel6 {
  /* for demo only: */
  background-color: cadetblue;
}

              
            
!

JS

              
                //--- DEFINE a reusable animation function: ---//
function scrollThere(targetElement, speed) {
  // initiate an animation to a certain page element:
  $('html, body').stop().animate(
    { scrollTop: targetElement.offset().top }, // move window so target element is at top of window
    speed, // speed in milliseconds
    'linear' // easing
  ); // end animate
} // end scrollThere function definition





//--- START SCROLL EVENTS ---//
// detect a mousewheel event (note: relies on jquery mousewheel plugin):
$(window).on('mousewheel', function (e) {

  // get Y-axis value of each div:
  var div1y = $('#panel1').offset().top,
      div2y = $('#panel2').offset().top,
      div3y = $('#panel3').offset().top,
      div4y = $('#panel4').offset().top,
      div5y = $('#panel5').offset().top,
      div6y = $('#panel6').offset().top,
      // get window's current scroll position:
      lastScrollTop = $(this).scrollTop(),
      // for getting user's scroll direction:
      scrollDirection,
      // for determining the previous and next divs to scroll to, based on lastScrollTop:
      targetUp,
      targetDown,
      // for determining which of targetUp or targetDown to scroll to, based on scrollDirection:
      targetElement;

  // get scroll direction:
  if ( e.deltaY > 0 ) {
    scrollDirection = 'up';
  } else if ( e.deltaY <= 0 ) {
    scrollDirection = 'down';
  } // end if

  // prevent default behavior (page scroll):
  e.preventDefault();

  // condition: determine the previous and next divs to scroll to, based on lastScrollTop:
  if (lastScrollTop === div1y) {
    targetUp = $('#panel1');
    targetDown = $('#panel2');
  } else if (lastScrollTop === div2y) {
    targetUp = $('#panel1');
    targetDown = $('#panel3');
  } else if (lastScrollTop === div3y) {
    targetUp = $('#panel2');
    targetDown = $('#panel4');
  } else if (lastScrollTop === div4y) {
    targetUp = $('#panel3');
    targetDown = $('#panel5');
  } else if (lastScrollTop === div5y) {
    targetUp = $('#panel4');
    targetDown = $('#panel6');
  } else if (lastScrollTop === div6y) {
    targetUp = $('#panel5');
    targetDown = $('#panel6');
    
  } else if (lastScrollTop < div2y) {
    targetUp = $('#panel1');
    targetDown = $('#panel2');
  } else if (lastScrollTop < div3y) {
    targetUp = $('#panel2');
    targetDown = $('#panel3');
  } else if (lastScrollTop < div4y) {
    targetUp = $('#panel3');
    targetDown = $('#panel4');
  } else if (lastScrollTop < div5y) {
    targetUp = $('#panel4');
    targetDown = $('#panel5');
  } else if (lastScrollTop < div6y) {
    targetUp = $('#panel5');
    targetDown = $('#panel6');
  } else if (lastScrollTop > div6y) {
    targetUp = $('#panel6');
    targetDown = $('#panel6');
  } // end else if

  // condition: determine which of targetUp or targetDown to scroll to, based on scrollDirection:
  if (scrollDirection === 'down') {
    targetElement = targetDown;
  } else if (scrollDirection === 'up') {
    targetElement = targetUp;
  } // end else if

  // scroll smoothly to the target element:
  scrollThere(targetElement, 700);

}); // end on mousewheel event
//--- END SCROLL EVENTS ---//


              
            
!
999px

Console