Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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 type="radio" id="from-end-0" name="from" checked />
<input type="radio" id="from-end-1" name="from" />
<input type="radio" id="from-start-1" name="from" />
<input type="radio" id="from-start-0" name="from" />

<input type="radio" id="to-end-0" name="to" />
<input type="radio" id="to-end-1" name="to" />
<input type="radio" id="to-start-1" name="to" />
<input type="radio" id="to-start-0" name="to" checked />

<div id="controls">
	<div>
		<h2>From offset</h2>
		<ul>
			<li><label for="from-start-0"><code>start 0</code></label></li>
			<li><label for="from-start-1"><code>start 1</code></label></li>
			<li><label for="from-end-1"><code>end 1</code></label></li>
			<li><label for="from-end-0"><code>end 0</code></label></li>
		</ul>
	</div>
	<div>
		<h2>To offset</h2>
		<ul>
			<li><label for="to-start-0"><code>start 0</code></label></li>
			<li><label for="to-start-1"><code>start 1</code></label></li>
			<li><label for="to-end-1"><code>end 1</code></label></li>
			<li><label for="to-end-0"><code>end 0</code></label></li>
		</ul>
	</div>
</div>

<div id="browser">
	<main>
		<div class="box" data-offset="end 0"></div>
		<div class="box" data-offset="end 1"></div>
		<div class="box" data-offset="start 1"></div>
		<div class="box" data-offset="start 0"></div>
		
		<div class="box" id="from"></div>
		<div class="box" id="to"></div>
	</main>
	<aside id="scrollbar">
		<div id="thumb"></div>
	</aside>
	<div id="animation-line"></div>
</div>
<div id="base-line"></div>
		

<details>
	<summary>ℹ️</summary>
	<dialog open>
		<h1>About this Pen</h1>
		<p>ℹ️ Scroll-Linked Animations with Element-Based offsets take a somewhat quirky syntax. This tool helps you visualize how long the animation will run, based on the selected offsets.</p>
		
		<p>🚦 Valid combinations result in a green line. Invalid Combinations result in a red line.</p>
		
		<p>🤔 Want to learn more about Scroll-Linked Animations / Scroll-Timeline? Check out these two articles:</p>
		
		<ul>
			<li><a href="https://brm.us/scroll-linked-animations-pt1" target="_top">Scroll-Linked Animations with <code>@scroll-timeline</code> (Part 1) — Introduction</a></li>
			<li><a href="https://brm.us/scroll-linked-animations-pt2" target="_top">Scroll-Linked Animations with <code>@scroll-timeline</code> (Part 2) — Element-Based Offsets</a></li>
		</ul>
		
		<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 {
	--scrollbox-border-size: 1rem;
	--scrollbox-height: 60vh;
	--scrollbox-width: 60vw;
	--box-height: 10vh;
	--box-border-size: 0.25rem;

	--thumb-size: 10vh;
	--scrollbar-width: 0.5rem;
	
	--shaded-size: 2px;
	--shaded-color: rgba(0 0 0 / 0.12);
}

html, body {
	width: 100vw;
	height: 100vh;
	background: #fff;
	margin: 0;
	padding: 0;
}

body {
	display: grid;
	place-items: center;
}

#browser {
	width: var(--scrollbox-width);
	height: var(--scrollbox-height);
	border: var(--scrollbox-border-size) solid lightblue;

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

	position: relative;
	z-index: 1;
}

#browser * {
	margin: 0;
	padding: 0;
}

main {
	position: relative;
	background: transparent;
}

main::before, main::after {
	white-space: nowrap;
	display: inline-block;
	position: absolute;
	right: -1rem;
	text-transform: uppercase;
	font-size: 0.8rem;
} 

main::before {
	content: 'start edge';
	top: 0;
	transform: translate3d(calc(1em + var(--scrollbox-border-size) + 100%), calc(-50% - var(--scrollbox-border-size) / 2), 0);
}

main::after {
	content: 'end edge';
	bottom: 0;
	transform: translate3d(calc(1em + var(--scrollbox-border-size) + 100%), calc(50% + var(--scrollbox-border-size) / 2), 0);
}

#scrollbar {
	grid-area: scrollbar;
	height: 100%;
	align-self: start;

	background: #ccc;
}

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

.box {
	height: var(--box-height);
	position: absolute;
	left: 0;
	right: 0;

	border-top: var(--box-border-size) dashed #333;
}

.box[data-offset] {
	background: repeating-linear-gradient(
      -45deg,
      var(--shaded-color),
      var(--shaded-color) var(--shaded-size),
      transparent var(--shaded-size),
      transparent calc(var(--shaded-size) * 2)
    );
}

.box[data-offset="end 0"] {
	transform: translateY(calc(var(--scrollbox-height) + var(--scrollbox-border-size)));
}

.box[data-offset="end 1"] {
	transform: translateY(calc(var(--scrollbox-height) - var(--box-height) - var(--box-border-size)));
}

.box[data-offset="start 1"] {
}

.box[data-offset="start 0"] {
	transform: translateY(calc(-1 * (var(--box-height) + var(--scrollbox-border-size) + var(--box-border-size))));
}

.box::after {
	text-transform: uppercase;
	font-size: 0.8rem;
	display: inline-block;
	position: absolute;
	left: 1rem;
	top: 50%;
	display: inline-block;
	content: attr(data-offset);
	transform: translate3d(
		0,
		-50%,
		0
	);
}

input {
	display: none;
}

#base-line,
#animation-line {
	width: 0;
	height: auto;
	
	border: 0.5em solid green;
	position: absolute;
	left: calc(50% - (var(--scrollbar-width) / 2));
	top: 50%;
	bottom: 50%;
}

#base-line {
	top: 0;
	bottom: 0;
	border-color: red;
}

#from-end-0:checked ~ #browser #animation-line {
	bottom: calc(var(--scrollbox-border-size) * -1)
}

#from-end-1:checked ~ #browser #animation-line {
	bottom: calc(var(--box-height) + var(--box-border-size));
}

#from-start-1:checked ~ #browser #animation-line {
	bottom: calc(var(--scrollbox-height))
}

#from-start-0:checked ~ #browser #animation-line {
	bottom: calc(var(--scrollbox-height) + var(--scrollbox-border-size));
}

#to-start-0:checked ~ #browser #animation-line {
	top: calc((var(--box-height) + var(--scrollbox-border-size) + var(--box-border-size)) * -1)
}

#to-start-1:checked ~ #browser #animation-line {
	top: 0;
}

#to-end-1:checked ~ #browser #animation-line {
	top: calc(var(--scrollbox-height) - var(--box-height) - var(--box-border-size));
}

#to-end-0:checked ~ #browser #animation-line {
	top: calc(var(--scrollbox-height) + var(--scrollbox-border-size));
}

#from {
	color: rgba(0 0 150 / 0.5);
}
#to {
	color: rgba(150 0 150 / 0.5);
}
#from::after {
	content: 'from';
}
#to::after {
	content: 'to';
}

#from, #to {
	width: 50%;
	left: 25%;
	
	--shaded-color: lime;
	background: repeating-linear-gradient(
      45deg,
      var(--shaded-color),
      var(--shaded-color) var(--shaded-size),
      transparent var(--shaded-size),
      transparent calc(var(--shaded-size) * 2)
    );
	border-top: var(--box-border-size) solid lime;
}

#from::after, #to::after {
	left: auto;
	right: 1rem;
	color: black;
}

#from-end-0:checked ~ #browser #from,
#to-end-0:checked ~ #browser #to {
	bottom: calc((var(--box-height) + var(--scrollbox-border-size) + var(--box-border-size)) * -1);
}

#from-end-1:checked ~ #browser #from,
#to-end-1:checked ~ #browser #to {
	bottom: 0;
}

#from-start-1:checked ~ #browser #from {
	top: 0;
}

#from-start-0:checked ~ #browser #from,
#to-start-0:checked ~ #browser #to {
	top: calc((var(--box-height) + var(--scrollbox-border-size) + var(--box-border-size)) * -1);
}

/* Invalid Combinations */
#from-start-0:checked ~ #to-start-0:checked ~ #browser #animation-line,
#from-start-0:checked ~ #to-start-1:checked ~ #browser #animation-line,
#from-start-0:checked ~ #to-end-1:checked ~ #browser #animation-line,
#from-start-0:checked ~ #to-end-0:checked ~ #browser #animation-line,
#from-start-1:checked ~ #to-start-1:checked ~ #browser #animation-line,
#from-start-1:checked ~ #to-end-1:checked ~ #browser #animation-line,
#from-start-1:checked ~ #to-end-0:checked ~ #browser #animation-line,
#from-end-1:checked ~ #to-end-1:checked ~ #browser #animation-line,
#from-end-1:checked ~ #to-end-0:checked ~ #browser #animation-line,
#from-end-0:checked ~ #to-end-0:checked ~ #browser #animation-line {
	border-color: red;
}

#controls {
	width: var(--scrollbox-width);
	display: flex;
	justify-content: space-evenly;
	text-align: center;

	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate3d(-50%, -50%, 0);
	z-index: 2;
}

#controls ul, #controls li {
	list-style: none;
	margin: 0;
	padding: 0;
}

#controls label {
	cursor: pointer;
}

#from-start-0:checked ~ #controls [for='from-start-0'],
#from-start-1:checked ~ #controls [for='from-start-1'],
#from-end-1:checked ~ #controls [for='from-end-1'],
#from-end-0:checked ~ #controls [for='from-end-0'],
#to-start-0:checked ~ #controls [for='to-start-0'],
#to-start-1:checked ~ #controls [for='to-start-1'],
#to-end-1:checked ~ #controls [for='to-end-1'],
#to-end-0:checked ~ #controls [for='to-end-0'] {
	font-weight: bold;
}

#controls [for]::before {
	content: '○ ';
}

#from-start-0:checked ~ #controls [for='from-start-0']::before,
#from-start-1:checked ~ #controls [for='from-start-1']::before,
#from-end-1:checked ~ #controls [for='from-end-1']::before,
#from-end-0:checked ~ #controls [for='from-end-0']::before,
#to-start-0:checked ~ #controls [for='to-start-0']::before,
#to-start-1:checked ~ #controls [for='to-start-1']::before,
#to-end-1:checked ~ #controls [for='to-end-1']::before,
#to-end-0:checked ~ #controls [for='to-end-0']::before {
	content: '● ';
}


/** 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

              
                import { showDialog } from 'https://codepen.io/bramus/pen/ZEqMOLz.js';
showDialog();
              
            
!
999px

Console