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

              
                <header class="header">
	<nav>
		<a href="https://cydstumpel.nl/" target="_blank">
			Cyd Stumpel
		</a>
		<p>
			Interaction observer example
		</p>
	</nav>
</header>
<img src="https://pbs.twimg.com/media/BcvmxibIYAAH8a3.jpg" />

              
            
!

CSS

              
                * {
	font-family: 'Helvetica Neue', Helvetica, sans-serif;
	margin: 0;
	box-sizing: border-box;
	color: inherit;
}

a {
	text-decoration: none;
}

.header {
	width: 100%;
	height: 5.75rem;
	&.background--dark nav {
		background: black;
		color: white;
	}
	nav {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		display: flex;
		justify-content: space-between;
		width: 100%;
		font-size: 1.5rem;
		padding: 2rem;
		transition: 0.4s ease-out;
		@media (max-width: 750px) {
      font-size: 1rem;
    }
	}
}

img {
	width: 100%;
	heigth: 150vh;
	object-fit: cover;
}
              
            
!

JS

              
                const header = document.querySelector('.header');
const inView = (entries) => {
  for (const entry of entries) {
    // try logging entry to view all the possible values
    if (entry.boundingClientRect.y < -32) {
      header.classList.add('background--dark'); // for example change the background of the header when the page has scrolled 32 px.
    } else {
      header.classList.remove('background--dark'); 
    }
  }
};
// threshold is just one of the options you can pass in the InteractionObserver
// It determines the amount of triggers while scrolling, it allows an array of numbers between 0 and 1
let threshold = []; 
for (let i = 0; i <= 100; i++) {
  threshold.push(i / 100);
}

const observePageHeader = new IntersectionObserver(inView, { threshold });

// observing the element that has .header as a class
observePageHeader.observe(header);
              
            
!
999px

Console