HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<nav>
<!--Shows our position on the timeline-->
<div class="marker"></div>
<!--Draggable element-->
<div class="nav__track" data-draggable>
<ul class="nav__list">
<li>
<a href="#section_1" class="nav__link" data-link><span>1993</span></a>
</li>
<li>
<a href="#section_2" class="nav__link" data-link><span>1995</span></a>
</li>
<li>
<a href="#section_3" class="nav__link" data-link><span>1997</span></a>
</li>
<li>
<a href="#section_4" class="nav__link" data-link><span>2000</span></a>
</li>
<li>
<a href="#section_5" class="nav__link" data-link><span>2001</span></a>
</li>
<li>
<a href="#section_6" class="nav__link" data-link><span>2003</span></a>
</li>
<li>
<a href="#section_7" class="nav__link" data-link><span>2007</span></a>
</li>
<li>
<a href="#section_8" class="nav__link" data-link><span>2011</span></a>
</li>
<li>
<a href="#section_9" class="nav__link" data-link><span>2016</span></a>
</li>
</ul>
</div>
</nav>
<main>
<section id="section_1" style="--i: 0">
<div class="container">
<h2 class="section__heading">
<span>1993</span>
<span>Pablo Honey</span>
</h2>
<div class="section__image">
<img src="https://assets.codepen.io/85648/radiohead_pablo-honey.jpg" width="1200" height="1200" />
</div>
</div>
</section>
<section id="section_2" style="--i: 1">
<div class="container">
<h2 class="section__heading">
<span>1995</span>
<span>The Bends</span>
</h2>
<div class="section__image">
<img src="https://assets.codepen.io/85648/radiohead_the-bends.webp" width="1200" height="1200" />
</div>
</div>
</section>
<section id="section_3" style="--i: 2">
<div class="container">
<h2 class="section__heading">
<span>1997</span>
<span>OK Computer</span>
</h2>
<div class="section__image">
<img src="https://assets.codepen.io/85648/radiohead_ok-computer.webp" width="1200" height="1200" />
</div>
</div>
</section>
<section id="section_4" style="--i: 3">
<div class="container">
<h2 class="section__heading">
<span>2000</span>
<span>Kid A</span>
</h2>
<div class="section__image">
<img src="https://assets.codepen.io/85648/radiohead_kid-a.webp" width="1200" height="1200" />
</div>
</div>
</section>
<section id="section_5" style="--i: 4">
<div class="container">
<h2 class="section__heading">
<span>2001</span>
<span>Amnesiac</span>
</h2>
<div class="section__image">
<img src="https://assets.codepen.io/85648/radiohead_amnesiac.webp" width="1200" height="1200" />
</div>
</div>
</section>
<section id="section_6" style="--i: 5">
<div class="container">
<h2 class="section__heading">
<span>2003</span>
<span>Hail to the Thief</span>
</h2>
<div class="section__image" style="--i: 6">
<img src="https://assets.codepen.io/85648/radiohead_hail-to-the-thief.webp" width="1200" height="1200" />
</div>
</div>
</section>
<section id="section_7" style="--i: 7">
<div class="container">
<h2 class="section__heading">
<span>2007</span>
<span>In Rainbows</span>
</h2>
<div class="section__image">
<img src="https://assets.codepen.io/85648/radiohead_in-rainbows.webp" width="1200" height="1200" />
</div>
</div>
</section>
<section id="section_8" style="--i: 8">
<div class="container">
<h2 class="section__heading">
<span>2011</span>
<span>The King of Limbs</span>
</h2>
<div class="section__image">
<img src="https://assets.codepen.io/85648/radiohead_king-of-linbs.webp" width="1200" height="1200" />
</div>
</div>
</section>
<section id="section_9" style="--i: 9">
<div class="container">
<h2 class="section__heading">
<span>2016</span>
<span>A Moon Shaped Pool</span>
</h2>
<div class="section__image">
<img src="https://assets.codepen.io/85648/radiohead_a-moon-shaped-pool.webp" width="1200" height="1200" />
</div>
</div>
</section>
</main>
* {
box-sizing: border-box;
}
html {
overscroll-behavior: contain;
@media (prefers-reduced-motion: no-preference) {
scroll-behavior: smooth;
}
}
body {
--activeColor: rgb(240 240 240);
--navBgColor: rgb(37 38 41);
--navTextColor: rgb(144 144 150);
--mainBg: rgb(20 20 23);
font-family: 'Syncopate', sans-serif;
min-height: 100vh;
margin: 0;
color: rgb(20 20 23);
background: var(--mainBg);
}
img {
display: block;
width: 100%;
height: auto;
max-width: 100%;
}
section {
--h: calc(var(--i) * 30);
min-height: 100vh;
padding: 8rem 0 max(5vh, 2rem);
display: flex;
justify-content: center;
align-items: center;
background-color: hsl(var(--h, 0) 75% 60%);
}
.container {
width: 100%;
max-width: 80rem;
padding: 0 max(5vw, 1rem);
transform-style: perspective-3d;
perspective: 900px;
@media (min-width: 32em) {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
gap: 1rem;
}
}
nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: var(--navBgColor);
color: var(--navTextColor);
z-index: 2;
height: 6rem;
&::after {
content: '';
position: absolute;
top: 1.7rem;
left: 0;
width: 100%;
height: 0.25rem;
background: currentColor;
pointer-events: none;
}
}
.marker {
position: fixed;
top: 1.75rem;
left: 4rem;
width: 1rem;
height: 1rem;
transform: translate3d(-50%, -50%, 0);
background: var(--activeColor);
border-radius: 100%;
z-index: 2000;
&::before {
content: '';
position: absolute;
top: calc(50% - 0.2rem);
right: 100%;
width: 4rem;
height: 0.4rem;
background-color: var(--activeColor);
}
}
.nav__track {
position: relative;
min-width: max(200rem, 200%);
padding: 1.5rem max(100rem, 100%) 0 0;
height: 6rem;
}
.nav__list {
list-style: none;
display: flex;
justify-content: space-between;
margin: 0;
padding: 0;
}
.nav__link {
position: relative;
display: block;
min-width: 8rem;
padding: 2.25rem 1rem 0.5rem;
text-align: center;
color: inherit;
text-decoration: none;
z-index: 1;
transition: color 150ms;
&:hover,
&:focus {
color: var(--activeColor);
text-decoration: underline;
}
&::after {
content: '';
position: absolute;
top: 0;
left: 50%;
width: 0.65rem;
height: 0.65rem;
background-color: currentColor;
border-radius: 50%;
transform: translate3d(-50%, 0, 0);
transform-origin: center center;
}
span {
display: block;
transition: transform 200ms;
}
&.is-active {
span {
transform: scale(1.4);
color: var(--activeColor);
}
&::after {
display: none;
}
}
}
.section__heading {
font-size: clamp(2rem, 12vmin, 7rem);
line-height: 1;
letter-spacing: -0.06em;
margin: 0 0 1rem;
grid-row: 1;
grid-column: 1 / span 7;
align-self: end;
position: relative;
z-index: 1;
span {
display: block;
}
span:first-child {
font-size: clamp(1rem, 10vmin, 5rem);
}
span:nth-child(2) {
word-break: break-word;
}
}
.section__image {
grid-row: 1;
grid-column: 5 / span 3;
position: relative;
box-shadow: 0.45rem 0.45rem 8rem rgb(0 0 0 / 0.3);
align-self: center;
&::after {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: hsl(var(--h, 0) 50% 50%);
mix-blend-mode: screen;
}
img {
filter: brightness(0.5) grayscale(100%);
}
}
import lodashThrottle from "https://cdn.skypack.dev/[email protected]";
const scrollContainer = document.querySelector('[data-scroller]')
const sections = gsap.utils.toArray('section')
const track = document.querySelector('[data-draggable]')
const navLinks = gsap.utils.toArray('[data-link]')
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)')
const lastItemWidth = () => navLinks[navLinks.length - 1].offsetWidth
const getUseableHeight = () => document.documentElement.offsetHeight - window.innerHeight
const getDraggableWidth = () => {
return ((track.offsetWidth * 0.5) - lastItemWidth())
}
const updatePosition = () => {
const left = track.getBoundingClientRect().left * -1
const width = getDraggableWidth()
const useableHeight = getUseableHeight()
const y = gsap.utils.mapRange(0, width, 0, useableHeight, left)
st.scroll(y)
}
const tl = gsap.timeline()
.to(track, {
x: () => getDraggableWidth() * -1,
ease: 'none'
})
const st = ScrollTrigger.create({
animation: tl,
scrub: 0,
})
const draggableInstance = Draggable.create(track, {
type: 'x',
inertia: true,
bounds: {
minX: 0,
maxX: getDraggableWidth() * -1
},
edgeResistance: 1,
onDragStart: () => st.disable(),
onDragEnd: () => st.enable(),
onDrag: updatePosition,
onThrowUpdate: updatePosition
})
const initSectionAnimation = () => {
/* Do nothing if user prefers reduced motion */
if (prefersReducedMotion.matches) return
sections.forEach((section, index) => {
const heading = section.querySelector('h2')
const image = section.querySelector('.section__image')
/* Set animation start state */
gsap.set(heading, {
opacity: 0,
y: 50
})
gsap.set(image, {
opacity: 0,
rotateY: 15
})
/* Create the timeline */
const sectionTl = gsap.timeline({
scrollTrigger: {
trigger: section,
start: () => 'top center',
end: () => `+=${window.innerHeight}`,
toggleActions: 'play reverse play reverse',
// toggleClass: 'is-active',
// markers: true,
}
})
/* Add tweens to the timeline */
sectionTl.to(image, {
opacity: 1,
rotateY: -5,
duration: 6,
ease: 'elastic'
})
.to(heading, {
opacity: 1,
y: 0,
duration: 2
}, 0.5)
/* Create a new timeline to add an active class to the nav link for the current section */
const sectionTl2 = gsap.timeline({
scrollTrigger: {
trigger: section,
start: 'top 20px',
end: () => `bottom top`,
toggleActions: 'play none play reverse',
onToggle: ({ isActive }) => {
const sectionLink = navLinks[index]
if (isActive) {
sectionLink.classList.add('is-active')
} else {
sectionLink.classList.remove('is-active')
}
}
}
})
})
}
initSectionAnimation()
/* Allow navigation via keyboard */
track.addEventListener('keyup', (e) => {
const id = e.target.getAttribute('href')
if (!id || e.key !== 'Tab') return
const section = document.querySelector(id)
const y = section.getBoundingClientRect().top + window.scrollY
st.scroll(y)
})
Also see: Tab Triggers