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

              
                <div class="scroller" data-scroller>
	<header data-header>
		<nav class="header__nav">
			<div class="header__left-content">
				<a class="header__home-link" href="#home"><svg width="118" height="202" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 118.7 202.6"><path d="M117.7 58c-1.3-5.7-3.5-11-5.8-16.2-5.5-12.1-13-22.7-23.6-30.9-5.2-4-10.8-7.4-17.1-9.6C67.8.1 64.4-.2 60.8.3c-1.8.2-3.4.9-4.2 3.2.4.2.8.4 1.2.7.5.4.9.8 2.1 1.9-11.2-2.9-20.3-.1-28.9 5-9.7 5.8-17.2 13.7-22.6 23.6-3.7 6.8-5.9 14.1-7.3 21.7C-1.6 71.6.8 86 8 99.6c2.9 5.6 7 10.3 11.7 14.9-1.7 3.8-1.7 3.8-.8 7.2.6 2.2 1.1 4.3 1.8 6.5 6.9 23 15.8 45.3 25.2 67.3.3.7.7 1.5 1.1 2.2 3.3 5.8 9.3 6.6 13.9 1.6 1.5-1.6 2.8-3.5 4-5.4 2.8-4.4 5.6-8.9 8.3-13.5 7-11.7 13.2-23.8 17.6-36.7 3.1-8.8 5-17.9 4.1-27.3 0-.5 0-1 .1-2.3.4-.3 1.4-.9 2.2-1.6 8.2-7.4 14.3-16.4 18.1-26.8 3.2-8.9 4.5-18.1 2.4-27.7zm-14.6 13.5C99 87.7 90 100.1 74.4 107.1c-7.9 3.6-16.4 4.5-24.9 3.1-12.9-2.1-22.2-9.3-28.3-20.7-5.1-9.5-6.4-19.7-5.1-30.3 1.7-13.9 7.7-25.6 18.5-34.7 7.6-6.4 16.2-10.1 26.2-10.7.5 0 1-.1 1.4-.1 2.3 0 4.1-.8 5.1-3.1 22.9 14.7 30.6 27.6 35.9 49.9.8 3.6.8 7.4-.1 11z"/><path d="M55.9 99c-9.3-.9-17.9-5.7-23.5-15.2-.7-1.2-1.2-2.6-1.6-4-.6-2-.8-4.1-.2-6.1.4-1.6 1.2-3 3-3.4 1.6-.3 2.8.5 3.7 1.7l2.4 3c2.9 3.5 6.3 6.3 10.4 8.3 3.8 1.9 7.8 2.7 12.1 2 1.3-.2 2.5-.4 3.8-.6.8-.1 1.6-.2 2.4-.2 1.8 0 3.5.5 4.4 2.3.8 1.8.3 3.5-.9 4.9-3.8 4.6-8.4 7.4-16 7.3zM68.1 60.4c.1-3.9 1.1-6.8 4.4-8.4 3.1-1.5 6.8-.9 9.3 1.5 2.6 2.5 3.8 5.5 2.7 9.1-.9 3.1-2.8 5.3-6 6.2-4.5 1.3-8.8-1.1-10-5.7-.2-1-.3-2.1-.4-2.7zM43 57.6c-.8-.1-1.8-.2-2.7-.4-6.6-.9-7.7-8.5-4.4-12.5 2.6-3.1 7.2-3.8 10.8-1.6 3.6 2.2 5.2 6.6 3.7 10.3-1.1 2.9-3.8 4.4-7.4 4.2z"/></svg></a>
			</div>
			<ul class="header__list">
				<li>
					<a href="#about-us" data-link>About us</a>
				</li>
				<li>
					<a href="#the-flavours" data-link>The flavours</a>
				</li>
				<li>
					<a href="#get-in-touch" data-link>Get in touch</a>
				</li>
			</ul>
		</nav>
	</header>
	<main>
		<section data-section="raspberry" id="home">
			<div class="container grid">
				<div class="section__img-col">
					<img class="section__img" src="https://assets.codepen.io/85648/ice-creams-03.svg" alt="drawing of three smiling ice cream scoops in a bowl" />
				</div>
				<div class="section__content-col">
					<h1>Happy Face Ice Cream Parlour</h1>
					<p>A little ice cream parlour with big dreams.</p>
					<p>We pride ourselves on flavours beyond your wildest dreams, and customer service that’s out of this world!</p>
					<p>Order your favourite flavours online, or call us today to find out how we can make your special occasions extra delightful!</p>
					<a class="section__link" href="#0">Shop now</a>
				</div>
			</div>
		</section>
		<section data-section="mint" id="about-us">
			<div class="container grid">
				<div class="section__img-col">
					<img src="https://assets.codepen.io/85648/ice-creams-04.svg" alt="smiling scoop of ice cream with drips" />
				</div>
				<div class="section__content-col">
					<h2>About us</h2>
					<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
				</div>
			</div>
		</section>
		<section data-section="vanilla" id="the-flavours">
			<div class="container grid">
				<div class="section__img-col">
					<img src="https://assets.codepen.io/85648/ice-creams-01.svg" alt="three happy ice creams" />
				</div>
				<div class="section__content-col">
					<h2>The flavours</h2>
					<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
				</div>
			</div>
		</section>
		<section data-section="chocolate" id="get-in-touch">
			<div class="container grid">
				<div class="section__img-col">
					<img class="section__img" src="https://assets.codepen.io/85648/ice-creams-02.svg" alt="spoon with drips" />
				</div>
				<div class="section__content-col">
					<h2 data-section-title>Get in touch</h2>
					<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
				</div>
			</div>
		</section>
	</main>
</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,700");

/* Variables */
:root {
	--mint: #5ae8d5;
	--chocolate: #573e31;
	--raspberry: #f2308e;
	--vanilla: #faf2c8;
	
	--headerText: var(--vanilla);
	--headerBg: var(--raspberry);
}

/* --Reset and boilerplate stuff-- */
* {
	box-sizing: border-box;
}

body {
	font-family: "Open Sans", sans-serif;
	margin: 0;
	background: var(--vanilla);
	color: var(--chocolate);
	line-height: 1.6;
}

ul {
	list-style: none;
	margin: 0;
	padding: 0;
}

svg {
	width: 100%;
	height: auto;
	fill: currentColor;
}

img {
	display: block;
	max-width: 100%;
}

h1 {
	line-height: 1.2;
}

@media (min-width: 40em) {
	body {
		font-size: 1.2rem;
	}
	
	h1 {
		font-size: 3.5rem;
	}
}

a {
	color: inherit;
	text-decoration: none;
}

section {
	padding: 5rem 0;
	min-height: 100vh;
	display: grid;
	place-items: center;
}
/* ----- */

/* --Header and marker-- */
header {
	position: fixed;
	width: 100%;
	padding: 0 max(1rem, 3vw);
	background-color: var(--headerBg);
	color: var(--headerText);
	font-weight: 700;
	transition: color 200ms, background-color 200ms;
}

header::after {
	display: none;
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: var(--markerWidth, 0);
	height: 0.4rem;
	background-color: currentColor;
	transform: translate3d(var(--markerLeft, 0), 0, 0);
	transition: transform 250ms, width 200ms, background-color 200ms;
	will-change: width;
}

@media (min-width: 40em) {
	header::after {
		display: block;
	}
}
/* ----- */

/* --Header SVG - not necessary for the demo, just for fun-- */
.header__home-link {
	position: absolute;
	top: 1rem;
	left: 1rem;
	width: 5.25rem;
	height: 5.25rem;
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 1.25rem;
	border-radius: 50%;
	background: var(--headerBg);
	color: var(--headerText);
	border: 0.3rem solid;
}
/* ----- */

/* --Layout stuff-- */
.section__img {
	max-width: 12rem;
	margin: 0 auto;
}

@media (min-width: 40em) {
	.section__img {
		max-width: none;
	}
}

section:last-child .section__img {
	max-width: 10rem;
}

.container {
	max-width: 60rem;
	padding: 0 min(2rem, 5vw);
}

@media (min-width: 40rem) {
	.grid {
		display: grid;
		align-items: center;
		grid-template-columns: 1fr 2fr;
		gap: 3rem;
	}
}

.header__nav {
	display: flex;
	align-items: center;
}

.header__list {
	display: none;
	margin-left: auto;
}

@media (min-width: 40rem) {
	.header__list {
		display: flex;
	}
}

.header__list a {
	display: block;
	padding: 1rem;
}
/* ----- */

/* --Secton specific styles, not related to demo-- */
.section__link {
	display: inline-block;
	background: var(--chocolate);
	padding: 1rem 1.5rem;
	color: var(--vanilla);
	border-radius: 0.5rem;
	font-weight: 700;
	margin-top: 1.5rem;
}
/* ----- */

/* --Section colors-- */
[data-section="raspberry"] {
	background-color: var(--raspberry);
	color: var(--vanilla);
}

[data-section="mint"]  {
	background-color: var(--mint);
	color: var(--chocolate);
}

[data-section="vanilla"] {
	background-color: var(--vanilla);
	color: var(--chocolate);
}

[data-section="chocolate"] {
	background-color: var(--chocolate);
	color: var(--vanilla);
}
/* ----- */

/* --Setting the custom properties for header colors-- */
[data-theme="raspberry"]  {
	--headerText: var(--raspberry);
	--headerBg: var(--vanilla);
}

[data-theme="mint"] {
	--headerText: var(--mint);
	--headerBg: var(--chocolate);
}

[data-theme="chocolate"]  {
	--headerText: var(--chocolate);
	--headerBg: var(--vanilla);
}
/* ----- */

/* --Setting the scroll root - because Codepen puts the content in an iframe-- */
.scroller {
	height: 100vh;
	width: 100%;
	overflow: auto;
}
/* ----- */

/* --Smooth scroll behaviour for links-- */
@media (prefers-reduced-motion: no-preference) {
	.scroller {
		scroll-behavior: smooth;
	}
}
/* ----- */
              
            
!

JS

              
                const header = document.querySelector('[data-header]')
const sections = [...document.querySelectorAll('[data-section]')]
const scrollRoot = document.querySelector('[data-scroller]')
const headerLinks = [...document.querySelectorAll('[data-link]')]

let prevYPosition = 0
let direction = 'up'

const options = {
	root: scrollRoot,
	rootMargin: `${header.offsetHeight * -1}px`,
	threshold: 0
}

const getTargetSection = (entry) => {
	const index = sections.findIndex((section) => section == entry.target)
	
	if (index >= sections.length - 1) {
	 return entry.target
	} else {
	 return sections[index + 1]
	}
}

const updateColors = (target) => {
	const theme = target.dataset.section
	header.setAttribute('data-theme', theme)
}

const shouldUpdate = (entry) => {
	if (direction === 'down' && !entry.isIntersecting) {
		return true
	}

	if (direction === 'up' && entry.isIntersecting) {
		return true
	}
	
	return false
}

const updateMarker = (target) => {
	const id = target.id
	
	if (!id) return
	
	let link = headerLinks.find((el) => {
		return el.getAttribute('href') === `#${id}`
	})
	
	link = link || headerLinks[0]
	
	const distanceFromLeft = link.getBoundingClientRect().left
	
	header.style.setProperty('--markerWidth', `${link.clientWidth}px`)
	header.style.setProperty('--markerLeft', `${distanceFromLeft}px`)
}

const onIntersect = (entries, observer) => {
	entries.forEach((entry) => {
		if (scrollRoot.scrollTop > prevYPosition) {
			direction = 'down'
		} else {
			direction = 'up'
		}
		
		prevYPosition = scrollRoot.scrollTop
		
		const target = direction === 'down' ? getTargetSection(entry) : entry.target
		
		if (shouldUpdate(entry)) {
			updateColors(target)
			updateMarker(target)
		}
	})
}

document.addEventListener('readystatechange', e => {
  if (e.target.readyState === 'complete') {
    updateMarker(sections[0])
  }
})

const observer = new IntersectionObserver(onIntersect, options)

sections.forEach((section) => {
	observer.observe(section)
})

              
            
!
999px

Console