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

              
                <input id="play" type="checkbox" /><label for="play">Set Scroll Position to Bottom</label>
<input id="bullettime" type="checkbox" /><label for="bullettime">Slow things down</label>
<input id="overflow" type="checkbox" /><label for="overflow">Hide overflowing content (Firefox fix)</label>

<label for="play" class="controlbutton" id="forwardbutton"></label>
<label for="play" class="controlbutton" id="backwardbutton"></label>

<div id="browser">
	<main>
		<h1>Lorem ipsum dolor</h1>
		<p>Sit amet, consectetur adipiscing elit. Nunc lectus eros, dapibus quis egestas eget, commodo et leo.</p>
		<p>Nulla est ipsum, elementum a neque a, maximus ultricies justo. Nulla tincidunt nec nulla eu malesuada. Etiam maximus massa nec auctor facilisis.</p>
		<p>Henean sed commodo nibh, porttitor efficitur nisl. Integer porta, libero at facilisis consectetur, velit lorem posuere enim, vulputate vulputate massa ante sed diam.</p>
		<div id="thething"></div>
		<h2>Morbi aliquam efficitur finibus.</h2>
		<p>Phasellus ornare ultricies purus vel hendrerit. Suspendisse id ultricies nisi. Pellentesque rutrum ante ut rhoncus gravida.</p>
		<p>Henean sed commodo nibh, porttitor efficitur nisl. Integer porta, libero at facilisis consectetur, velit lorem posuere enim, vulputate vulputate massa ante sed diam.</p>
		<p>Nulla est ipsum, elementum a neque a, maximus ultricies justo. Nulla tincidunt nec nulla eu malesuada. Etiam maximus massa nec auctor facilisis.</p>
		<h2>Morbi aliquam.</h2>
		<p>Henean sed commodo nibh, porttitor efficitur nisl. Integer porta, libero at facilisis consectetur, velit lorem posuere enim, vulputate vulputate massa ante sed diam.</p>
		<h3>Morbi aliquam efficitur finibus.</h3>
		<p>Phasellus ornare ultricies purus vel hendrerit.</p>
	</main>
	<aside id="scrollbar">
		<div id="thumb"></div>
	</aside>
</div>

<details>
	<summary>ℹ️</summary>
	<dialog open>
		<h1>About this Pen</h1>
		<p>ℹ️ Scroll-Linked Animations are animations are linked to the scroll offset of a scroll container. Using element-based offset you can start/stop an animation as the targeted element appears and disappears from its scrollcontainer.</p>
		
		<p>👉 By default the animation starts when the top edge of the subject starts appearing into the scrollcontainer. The animation is done when the bottom edge of the subject is out of view.</p>
		
		<p>☑️ In this demo you can't scroll yourself, but can fake a scroll using the “Set Scroll Position to Bottom” control at the top left.</p>
		
		<p>👀 More animations/visualizations: <a href="https://codepen.io/collection/AYoego" target="_top">https://codepen.io/collection/AYoego</a></p>
		
		<p>👋 Built by Bramus! — <a href="https://www.twitter.com/bramus" target="_top">@bramus</a> - <a href="https://www.bram.us/" target="_top">https://www.bram.us/</a> </p>
	</dialog>
</details>
              
            
!

CSS

              
                :root {
	--browser-size--ul: 35; /* in vmin */
	--content-size--ul: calc(var(--browser-size--ul) * 3);
	--thumb-size--ul: calc(
		var(--browser-size--ul) / var(--content-size--ul) * var(--browser-size--ul)
	);

	--browser-size: calc(var(--browser-size--ul) * 1vmin);
	--browser-width: calc(var(--browser-size) * 4 / 3);
	--content-size: calc(var(--content-size--ul) * 1vmin);
	--thumb-size: calc(var(--thumb-size--ul) * 1vmin);

	--scrollbar-width: 1vmin;
}

html,
body {
	width: 100vw;
	height: 100vh;
	display: grid;
	place-items: center;
	overflow: hidden;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}

#browser {
	height: var(--browser-size);
	width: var(--browser-width);

	outline: 10px solid lightblue;

	display: grid;
	grid-template-columns: 1fr var(--scrollbar-width);
	grid-template-rows: 1fr;
	grid-template-areas: "content scrollbar";

	position: relative;
}

#browser * {
	transition: transform 3s linear, margin-top 3s linear;
}

main {
	font-family: "BLOKK";
	font-size: 2.5vmin;
	padding: 1rem;
	color: #999;
	line-height: 0.6; /* 🦊 Firefox Fix. Without it the line-height is waaaay off */

	grid-area: content;
	height: var(--content-size);
	overflow: hidden;

	outline: 1px solid grey;
	z-index: -1;
}

#scrollbar {
	grid-area: scrollbar;
	height: var(--browser-size);
	align-self: start;

	background: #ccc;
}

#scrollbar #thumb {
	top: 0;
	height: var(--thumb-size);
	width: 100%;
	background: #333;
	border-radius: 9999px;
}

#thething {
	width: 100%;
	height: 0;
	padding-top: 40%;
	background: red;
	position: relative;
}

#thething::after {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
	content: 'not intersecting';
	display: block;
	position: absolute;
	top: 0; right: 0; bottom: 0; left: 0;
	color: #fff;
	
	display: grid;
	place-items: center;
}

#thething.is-intersecting {
	background-color: green;
}

#thething.is-intersecting::after {
	content: 'intersecting';
}


/* Controls */
.controlbutton {
	position: fixed;
	top: 50%;
	left: 50%;
	z-index: 2;
	transform: translateX(calc((var(--browser-width) / 2) + 2em)) translateY(var(--offset)) rotate(90deg);
}

#forwardbutton {
	--offset: 75%;
}

#backwardbutton {
	--offset: -75%;
}

.controlbutton::after {
	font-size: 2em;
	cursor: pointer;
}

#forwardbutton::after {
	content: '⏭';
}

#backwardbutton::after {
	content: '⏮';
}

#play ~ #forwardbutton,
#play:checked ~ #backwardbutton {
	opacity: 1;
	pointer-events: auto;
}

#play:checked ~ #forwardbutton,
#play ~ #backwardbutton{
	opacity: 0.5;
	pointer-events: none;
}

/* Checkboxes */
#play,
#bullettime,
#overflow,
#play + label,
#bullettime + label,
#overflow + label {
	position: fixed;
	left: 1rem;
	margin: 0;
}
#play + label,
#bullettime + label,
#overflow + label {
	left: 2.25rem;
	white-space: nowrap;
}

#play,
#play + label {
	top: 1rem;
}
#bullettime,
#bullettime + label {
	top: 2.5rem;
}
#overflow,
#overflow + label {
	top: 4rem;
}

#bullettime:checked ~ #browser * {
	transition-duration: 10s;
}

/* Respond too checkboxes */
#play:checked ~ #browser main {
	transform: translateY(calc(-100% + var(--browser-size)));
}
#play:checked ~ #browser #thumb {
	/* 🪓 Hack: we animate margin-top to force repaints so that 
	   our IntersectionObserver will kick into action … (Safari Fix)
	*/
	margin-top: calc(var(--browser-size) - var(--thumb-size));
}
#overflow:checked ~ #browser {
	overflow: hidden;
}

/** Poor man's infobox */
details {
	position: fixed;
	bottom: 1em;
	right: 1em;
	font-size: clamp(1.25rem, 2vw, 2rem);
	z-index: 9999;
}
dialog[open] {
	position: fixed;
	top: 10vmin;
	right: 10vmin;
	bottom: 10vmin;
	left: 10vmin;
	width: auto;
	height: auto;

	/* Extra CSS for Safari … */
	background: #eee;
	border: 0.25em solid lightblue;
	padding: 1em;
	overflow: auto;
}
details[open] > summary::after {
	content: '';
	position: fixed;
	top: 0; right: 0; bottom: 0; left: 0;
	background: rgba(0 0 0 / 0.5);
	display: block;
}

/* Hide summary arrow …*/
details summary::-webkit-details-marker {
	display: none;
}
details summary {
	display: inline-block;
}
details summary::marker {
	display: none;
}
              
            
!

JS

              
                window.addEventListener('DOMContentLoaded', () => {

	const observer = new IntersectionObserver(entries => {
		entries.forEach(entry => {
			if (entry.isIntersecting) {
				entry.target.classList.add('is-intersecting');
			} else {
				entry.target.classList.remove('is-intersecting');
			}
		});
	}, {
		root: document.querySelector('#browser'),
		rootMargin: '0% 0% 0% 0%',
	});

	// Track #thething
	observer.observe(document.querySelector('#thething'));
	
});
              
            
!
999px

Console