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

              
                <article class="page">

  <article class="main">
    <div class="scroll-intro" id="intro">
      <div class="inner">
        <h1>CSS Scroll Snap Points Example</h1>
        <div class="supports" id="supports"></div>
        <p>With scroll snapping we can make it so that as you scroll the container, the browser will stop in the center of the slider and also the center of the image (if there is enough space allowed)</p>
      </div>
    </div>
    <div class="inner">
      <div class="scroll-container diff-size">
        <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/flower-sand.jpg">
        <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/man-thinking.jpg">
        <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/man-laughing.jpg">
        <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/piggy-bank.jpg">
        <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/couple-smiling.jpg">
        <img class="scroll-section" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/man-luggage.jpg">
      </div>
    </div>
  </article>
  <p class="p">Demo by Simon Codrington. <a href="http://www.sitepoint.com/intuitive-scrolling-interfaces-with-css-scroll-snap-points">See article</a>.</p>
</article>
              
            
!

CSS

              
                /*UNIVERSAL STYLES*/

html {
  font-size: 62.5%;
}

body {
  font-weight: 400;
  font-style: normal;
  font-size: 1.5rem;
  line-height: 1.5rem;
  color: #333;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 150%;
  margin: 1.5rem 0rem;
}

h1 {
  font-size: 3.8rem;
  margin: 0 0rem;
}

h2 {
  font-size: 2.8rem;
  margin: 0 0rem;
}

h3 {
  font-size: 2.1rem;
  margin: 0 0rem;
}

h4 {
  font-size: 1.8rem;
}

h5 {
  font-size: 1.3rem;
}

h6 {
  font-size: 1.0rem;
}

p {
  margin: 0rem 0rem 2.4rem 0rem;
  line-height: 170%;
}
/*clearfixes*/

.cf:before,
.cf:after {
  content: " ";
  display: table;
}

.cf:after {
  clear: both;
}

*,
*:before,
*:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
/*block level elements*/

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section,
div {
  margin: 1.5rem 0rem;
}

div {
  margin: 0rem;
}

.page {
  margin: 0px;
  padding: 0px;
}

.main {
  margin: 0px;
  padding: 0px;
  max-width: none;
}

.inner {
  max-width: 1000px;
  margin: auto;
  padding-left: 15px;
  padding-right: 15px;
}

.failure {
  color: red;
}

.success {
  color: green;
}
/*SCROLL SNAP SYLES*/

.scroll-container {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  width: 100%;
  height: 400px;
  scroll-snap-type: mandatory;
  scroll-behavior: smooth;
  background: #eee;
  border: solid 1px #ccc;
  font-size: 0px;
  margin-bottom: 50px;
}

.scroll-container .scroll-section {
  display: inline-block;
  vertical-align: middle;
  background: #fff;
  border: solid 1px #ccc;
  white-space: nowrap;
}
/*Slider X (different sized images)*/

.scroll-container.diff-size {
  scroll-snap-destination: 50% 0%;
  padding: 20px 0px;
}

.scroll-container.diff-size .scroll-section {
  width: auto;
  height: 100%;
  margin-right: 15px;
  scroll-snap-coordinate: 50% 0%;
}

.scroll-container.diff-size .scroll-section:first-child {
  scroll-snap-coordinate: 0% 0%, 50% 0%;
  margin-left: 15px;
}

.scroll-container.diff-size .scroll-section:last-child {
  scroll-snap-coordinate: 50% 0%, 100% 0%;
}

.p {
  text-align: center;
  padding-top: 80px;
  font-size: 13px;
}
              
            
!

JS

              
                $(function() {
  // detect if we support scroll snap or not (not the best but should work)
  var scrollSnap = false;
  scrollSnap = 'webkitScrollSnapType' in document.documentElement.style;
  scrollSnap = 'scrollSnapType' in document.documentElement.style;

  if (scrollSnap === true) {
    $('#supports').append('<h3 class="success">It looks like your browser does support scroll snap!</h3>');
  } else {
    $('#supports').append('<h3 class="failure">It looks like your browser might not support scroll snap properties</h3>');
  }
});
              
            
!
999px

Console