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="showprogressbar" type="checkbox" checked="checked" /><label for="showprogressbar">Show Progressbar</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">
	<div id="progress"></div>
	<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>
		<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. As you scroll back and forth the scroll container, you will see the animation timeline advance or rewind as you do so.</p>
		
		<p>👉 A typical example is a progress bar shown on top of a page: there is a direct link between the scroll progress and visible size of the progress bar.</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);
	--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: calc(var(--browser-size) * 4 / 3);

	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;
}

main {
	font-family: "BLOKK";
	font-size: calc(2vmin + 0.2em);
	padding: 1rem;
	color: #999;

	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;
}

#progress {
	position: absolute;
	top: 0;
	left: 0;
	right: var(--scrollbar-width);
	height: 1vmin;
	background: red;

	transform-origin: 0 50%;
	transform: scaleX(0);

	opacity: 0; /* Hide by default */
}

/* Controls */
.controlbutton {
	position: fixed;
	top: 50%;
	left: 50%;
	z-index: 2;
	transform: translateX(calc(-50% + var(--offset))) translateY(calc(-4rem + (var(--browser-size) / -2)));
}

#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,
#showprogressbar,
#overflow,
#play + label,
#showprogressbar + label,
#overflow + label {
	position: fixed;
	left: 1rem;
	margin: 0;
}
#play + label,
#showprogressbar + label,
#overflow + label {
	left: 2.25rem;
	white-space: nowrap;
}

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

/* Respond too checkboxes */
#play:checked ~ #browser main {
	transform: translateY(calc(-100% + var(--browser-size)));
}
#play:checked ~ #browser #thumb {
	transform: translateY(calc(var(--browser-size) - var(--thumb-size)));
}
#showprogressbar:checked ~ #browser #progress {
	opacity: 1;
}
#play:checked ~ #browser #progress {
	transform: scaleX(1);
}
#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

              
                
              
            
!
999px

Console