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

              
                <h1>Conditional Scroll Indicators with Scroll-Driven Animations</h1>

<main>
  <div class="container">
  <div class="up">
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="20">
      <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 15.75l7.5-7.5 7.5 7.5" />
    </svg>
  </div>
  
  <div contenteditable>
    CSS, short for Cascading Style Sheets, is a programming language that is used to describe the presentation or visual layout of a document written in HTML. It acts as a styling tool and enables web developers to control the appearance of their websites or web pages by specifying how different elements should be displayed on the screen. CSS allows designers to define various aspects such as font styles, colors, spacing between elements, background images, and much more.

    The term "cascading" in CSS refers to its ability to apply multiple stylesheets simultaneously and prioritize them based on their importance or specificity. This feature allows developers to create consistent designs across multiple web pages by defining common styles in an external stylesheet which can then be linked to all relevant HTML documents. Additionally, CSS makes it easy to update the design of an entire website by simply modifying one central stylesheet rather than having to manually edit each individual webpage.

    CSS can be applied directly within an HTML document using inline stylesheets or internally through embedded stylesheets within the head section of a page. However, it is considered best practice and more efficient from both maintenance and performance perspectives to use external style sheets stored separately in .css files which are then referenced within HTML documents.

    One important concept in CSS is selectors. Selectors allow you to target specific elements within your HTML markup so that you can apply different styles only where needed. Selectors can target tags (e.g., p, div), classes (e.g., .header), IDs (e.g., #main), attributes (e.g., [type="submit"]), pseudo-classes (e.g., :hover) and many other properties of DOM elements.

    Overall, CSS plays a crucial role in modern web development as it provides great flexibility and control over how content looks on websites. By separating style from structure with this powerful language, developers are able to create visually appealing websites while maintaining clean code that adheres to best practices for web accessibility and user experience.
  </div>
  
  <div class="down">
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="20">
      <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" />
    </svg>
  </div>
</div>

<div class="container">
  <div class="up">
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="20">
      <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 15.75l7.5-7.5 7.5 7.5" />
    </svg>
  </div>
  
  <div contenteditable>
    CSS, short for Cascading Style Sheets. The content of this box is short as well.
  </div>
  <div class="down">
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="20">
      <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" />
    </svg>
  </div>
</div>
</main>

<footer>
  <p>Demo for <a href="https://brm.us/css-scroll-detection" target="_top">https://brm.us/css-scroll-detection</a><br>Forked + Adjusted from <a href="https://codepen.io/shuding/pen/WNLGQor" target="_top">https://codepen.io/shuding/pen/WNLGQor</a> by <a href="https://twitter.com/shuding_/status/1698176794124578923" target="_top">Shu Ding</a></p>
</footer>
              
            
!

CSS

              
                @keyframes detect-scroll {
  from, to { --can-scroll: ;}
}

.container {
  height: 250px;
  width: 250px;
  overflow-y: auto;
  scroll-timeline: --scroll-timeline y;
  padding: 0 1em;
  position: relative;
  background: #fff;
  margin: auto;
  border-radius: .3em;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  
  animation: detect-scroll;
  animation-timeline: --scroll-timeline;
  animation-fill-mode: none;
}


* {
  box-sizing: border-box;
}

body {
  font-size: 17px;
  font-family: -system-ui, sans-serif;
  line-height: 1.5;
  letter-space: -0.01em;
  margin: 0;
  padding: 2em;
  color: #444;
  background: #cfcfcf;
  -webkit-font-smoothing: antialiased;
  
  display: grid;
  place-content: safe center;
  height: 100%;
  gap: 2rem;
}

html, body {
  height: 100%;
}

h1 {
	margin: 0;
	padding: 0;
	text-align: center;
}

main {
	display: flex;
  gap: 2rem;
	margin: 0 auto;
	text-align: center;
}

.content {
  min-height: 244px;
}

.up, .down {
  position: sticky;
  display: flex;
  justify-content: center;
  left: 0;
  right: 0;
  width: 100%;
  height: 1.5em;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  
  animation-name: reveal;
  animation-timeline: --scroll-timeline;
  animation-fill-mode: both;
  animation-range: 20px 40px;
  
  --visibility-if-can-scroll: var(--can-scroll) visible;
  --visibility-if-cant-scroll: hidden;
  visibility: var(--visibility-if-can-scroll, var(--visibility-if-cant-scroll));
}

.up {
  top: 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}

.down {
  bottom: 0;
  animation-direction: reverse;
  animation-range: calc(100% - 40px) calc(100% - 20px);
  border-top: 1px solid rgba(0, 0, 0, 0.2);
}

@keyframes reveal {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

footer {
  text-align: center;
  font-style: italic;
  font-size: 80%;
}
              
            
!

JS

              
                
              
            
!
999px

Console