Pen Settings

HTML

CSS

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

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

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.

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

              
                <div class="header">
  <h2>Lorem Ipsum</h2>
  <div id="scroll-indicator"></div>
</div>
<div id="contents"></div>
              
            
!

CSS

              
                body {
  margin: 0px;
}

.header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: fixed;
  width: 100%;
  text-align: center;
  border-bottom: 1px solid gray;
  background-color: whitesmoke;
}

#scroll-indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background-color: deepskyblue;
  transform: translateX(-100%);
}

#contents {
  padding: 10px;
}

              
            
!

JS

              
                const scrollIndicator = document.getElementById("scroll-indicator");
const contents = document.getElementById("contents");

fetch("https://baconipsum.com/api/?type=all-meat&paras=200&format=html")
  .then((response) => response.text())
  .then((result) => (contents.innerHTML = result));

window.addEventListener("scroll", (e) => {
  // clientHeight : 웹 브라우저 창의 높이
  // scrollTop : 현재 스크롤된 부분의 맨 위의 높이
  // scrollHeight : 문서의 총 높이 (= 스크롤의 총 높이)
  // contentHeight : 전체 총 높이에서 클라이언트 높이를 뺀 것

  const { scrollTop, scrollHeight, clientHeight } = e.target.scrollingElement;
  const contentHeight = scrollHeight - clientHeight;
  const percentage = (scrollTop / contentHeight) * 100;

  scrollIndicator.style.transform = `translateX(-${100 - percentage}%)`; // -100% ~ 0%
  scrollIndicator.style.transition = `transform 0.5 ease-out`; // 부드러운 애니메이션
});

              
            
!
999px

Console