Pen Settings



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


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


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.


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.


                <div class="fixed">not scrolling</div>

<div class="boundary"></div>


                body {
  margin: 0;
  height: 2000px;
  background: linear-gradient(to bottom, tomato, blueviolet 25%, slateblue 75%, darkslateblue 100%);
  font: normal 16px/1.5 sans-serif;

.fixed {
  padding: 20px;
  background: white;
  position: fixed;
  top: 0;
  left: 20px;
  right: 20px;
  box-shadow: 0 2px 4px rgba(10, 10, 10, 0.5);

.fixed.unfixed {
  position: absolute;

.boundary {
  position: absolute;
  top: 400px;
  width: 100%;
  border-top: 10px dashed purple;


                const fixed = document.querySelector('.fixed')
const boundary = document.querySelector('.boundary')

function debounce (cb, wait) {
	let timeout
	return function () {
		timeout = setTimeout(cb, wait)

let animationFrame, startScroll, boundaryTop, fixedHeight

function startLoop () {
  animationFrame = window.requestAnimationFrame(() => {
    const scroll = window.scrollY
    const atBoundary = (scroll - startScroll + fixedHeight) >= boundaryTop
    const isFixed = fixed.classList.contains('unfixed')

    if (atBoundary && !isFixed) {
      console.log(boundaryTop) = startScroll + boundaryTop - fixedHeight + 'px'
    if (!atBoundary && isFixed) {
      fixed.classList.remove('unfixed') = null

function endLoop () {

function scrollStart () {
  fixed.innerHTML = 'scrolling'
  window.removeEventListener('scroll', scrollStart)
  window.addEventListener('scroll', dbScrollEnd)
  // only do this work once
  fixedHeight = fixed.offsetHeight
  startScroll = window.pageYOffset
  boundaryTop = boundary.getBoundingClientRect().top

function scrollEnd () {

  fixed.innerHTML = 'not scrolling'
  window.removeEventListener('scroll', dbScrollEnd)
  window.addEventListener('scroll', scrollStart)

const dbScrollEnd = debounce(scrollEnd, 300)

window.addEventListener('scroll', scrollStart)