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

              
                <h2>Indicating Scrollable Content</h2>
<p>In a scrollbox or any area where the content is larger than its container, how do we indicate that there is more content to scroll down to, given that we can't always rely on the scrollbar being visible, especially on mobile?</p>

<div class="examples">
  
  <div id="example1" class="container">
    <ul class="list">
      <li class="item">One</li>
      <li class="item">Two</li>
      <li class="item">Three</li>
      <li class="item">Four</li>
      <li class="item">Five</li>
      <li class="item">Six</li>
      <li class="item">Seven</li>
      <li class="item">Eight</li>
      <li class="item">Nine</li>
      <li class="item">Ten</li>
    </ul>
  </div>
  <div class="explanation">
    <h3>Example 1</h3>
    <p>This is the original problem with no solution added.</p>
  </div>
  
  <div id="example2" class="container">
    <ul class="list">
      <li class="item">One</li>
      <li class="item">Two</li>
      <li class="item">Three</li>
      <li class="item">Four</li>
      <li class="item">Five</li>
      <li class="item">Six</li>
      <li class="item">Seven</li>
      <li class="item">Eight</li>
      <li class="item">Nine</li>
      <li class="item">Ten</li>
    </ul>
  </div>
  <div class="explanation">
    <h3>Example 2</h3>
    <p>This sets the height of each item so that the final item is partially shown. This technique relies on the items being of fixed height. This is more common used horizontally for large cards.</p>
  </div>
  
  <div id="example3" class="container off-bottom">
    <div class="scrollbox">
      <ul class="list">
        <li class="item">One</li>
        <li class="item">Two</li>
        <li class="item">Three</li>
        <li class="item">Four</li>
        <li class="item">Five</li>
        <li class="item">Six</li>
        <li class="item">Seven</li>
        <li class="item">Eight</li>
        <li class="item">Nine</li>
        <li class="item">Ten</li>
      </ul>
    </div>
    <div class="shadow shadow-top" aria-hidden="true"></div>
    <div class="shadow shadow-bottom" aria-hidden="true"></div>
  </div>
  <div class="explanation">
    <h3>Example 3</h3>
    <p>This uses shadows inside a scrollbox, which are dynamically added and removed as the ends of the scrollable range are reached.</p>
  </div>
  
  <div id="example4" class="container off-bottom">
    <div class="scrollbox">
      <ul class="list">
        <li class="item">One</li>
        <li class="item">Two</li>
        <li class="item">Three</li>
        <li class="item">Four</li>
        <li class="item">Five</li>
        <li class="item">Six</li>
        <li class="item">Seven</li>
        <li class="item">Eight</li>
        <li class="item">Nine</li>
        <li class="item">Ten</li>
      </ul>
    </div>
    <div class="shadows" aria-hidden="true"></div>
  </div>
  <div class="explanation">
    <h3>Example 4</h3>
    <p>Similar to the previous example, this adds a fade to the bottom of the scrollbox to hint at more content by showing the last few items gradually fading away. It dynamically disappears when you reach the bottom of the list.</p>
  </div>
  
  <div id="example5" class="container show-icon">
    <div class="scrollbox">
      <ul class="list">
        <li class="item">One</li>
        <li class="item">Two</li>
        <li class="item">Three</li>
        <li class="item">Four</li>
        <li class="item">Five</li>
        <li class="item">Six</li>
        <li class="item">Seven</li>
        <li class="item">Eight</li>
        <li class="item">Nine</li>
        <li class="item">Ten</li>
      </ul>
    </div>
    <div class="icon" aria-hidden="true"></div>
  </div>
  <div class="explanation">
    <h3>Example 5</h3>
    <p>This uses a CSS arrow icon to hint at more content. Not quite as subtle, the idea for this one is taken from gaming. It's dynamically removed when it reaches the bottom.</p>
  </div>
  
</div>
              
            
!

CSS

              
                body {
  background-image:linear-gradient(skyblue, white);
  background-repeat:no-repeat;
  box-sizing:border-box;
  font-family:sans-serif;
  margin:2em;
  min-height:100vh;
}

p {
  max-width:44em;
}

.examples {
  display:flex;
  flex-wrap:wrap;
  margin:-.5em;
}

.container {
  background-color:white;
  border:solid .5em black;
  border-radius:.5em;
  box-sizing:border-box;
  flex:0 0 30%;
  height:240px;
  margin:.5em;
  overflow:auto;
}

.explanation {
  flex: 1 0 60%;
  margin-left:1em;
}

.list {
  list-style:none;
  margin:0;
  padding:0;
}

.item {
  background-color:lightgray;
  margin:.25em;
  padding:.5em;
}

// examples

#example2 {
  .list {
    height:100%;
  }
  .item {
    height:20%;
  }
}

#example3 {
  overflow:hidden;
  position:relative;
  .scrollbox {
    height:100%;
    overflow:auto;
  }
  .shadow {
    bottom:0;      
    left:0;
    pointer-events:none;
    position:absolute;
    right:0;
    top:0;
    transition:all .2s ease-out;
  }
  &.off-top {
    .shadow-top {
      box-shadow:0 1em 1em -1em black inset;
    }
  }
  &.off-bottom {    
    .shadow-bottom {
      box-shadow:0 -1em 1em -1em black inset;
    }
  }
}

#example4 {
  overflow:hidden;
  position:relative;
  .scrollbox {
    height:100%;
    overflow:auto;
  }
  .shadows {
    bottom:0;      
    left:0;
    pointer-events:none;
    position:absolute;
    right:0;
    top:0;
    transition:all .2s ease-out;
  }
  &.off-bottom {    
    .shadows {
      box-shadow:0 -3em 3em -1em white inset;
    }
  }
}

#example5 {
  overflow:hidden;
  position:relative;
  .scrollbox {
    height:100%;
    overflow:auto;
  }
  .icon {
    border:solid 2em transparent;
    border-top-color:white;
    bottom:-1.5em;
    color:white;
    height:0;
    left:50%;
    opacity:0;
    pointer-events:none;
    position:absolute;
    right:0;
    text-align:center;
    transform:translate(-50%, 0);
    transition:all .2s ease-out;
    width:0;
  }
  &.show-icon {
    .icon {
      animation:flash 1.5s infinite linear;
      // opacity:1;
    }
  }
}

@keyframes flash {
  0%, 100% {
    opacity:1;
  }
  50% {
    opacity:.2;
  }
}
              
            
!

JS

              
                const example3 = document.getElementById('example3');
const example3sb = document.querySelector('#example3 .scrollbox');
let example3IsScrolling = false;

function setShadows(event) {
  if (!example3IsScrolling) {
    window.requestAnimationFrame(function() {
      if (event.target.scrollTop > 0) {
        example3.classList.add('off-top');
      }
      else {
        example3.classList.remove('off-top');
      }
      if (event.target.scrollTop < 160) {
        example3.classList.add('off-bottom');
      }
      else {
        example3.classList.remove('off-bottom');
      }
      example3IsScrolling = false;
    });
    example3IsScrolling = true;
  }
}

example3sb.addEventListener('scroll', setShadows);

//////////////////////////////////

const example4 = document.getElementById('example4');
const example4sb = document.querySelector('#example4 .scrollbox');
let example4IsScrolling = false;

function setFade(event) {
  if (!example4IsScrolling) {
    window.requestAnimationFrame(function() {
      if (event.target.scrollTop < 160) {
        example4.classList.add('off-bottom');
      }
      else {
        example4.classList.remove('off-bottom');
      }
      example4IsScrolling = false;
    });
    example4IsScrolling = true;
  }
}

example4sb.addEventListener('scroll', setFade);

//////////////////////////////////

//////////////////////////////////

const example5 = document.getElementById('example5');
const example5sb = document.querySelector('#example5 .scrollbox');
let example5IsScrolling = false;

function setFade(event) {
  if (!example5IsScrolling) {
    window.requestAnimationFrame(function() {
      if (event.target.scrollTop < 160) {
        example5.classList.add('show-icon');
      }
      else {
        example5.classList.remove('show-icon');
      }
      example5IsScrolling = false;
    });
    example5IsScrolling = true;
  }
}

example5sb.addEventListener('scroll', setFade);
              
            
!
999px

Console