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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<div class="container">
<div class="jumps">Jump to: <a href="#end" id="link">bottom</a> | <a href="#top">top</a></div>
<section class="panel pin">
<div class="standard">
<h2>Standard behavior</h2>
<div class="boxes">
<div class="box box-1 gradient-blue">1</div>
<div class="box box-2 gradient-red">2</div>
<div class="box box-3 gradient-green">3</div>
<div class="box box-4 gradient-purple">4</div>
<div class="box box-5">5</div>
</div>
</div>
<div class="features">
<div class="boxes">
<div class="box box-1 gradient-blue">1</div>
<div class="box box-2 gradient-red">2</div>
<div class="box box-3 gradient-green">3</div>
<div class="box box-4 gradient-purple">4</div>
<div class="box box-5">5</div>
</div>
<h2>With features:</h2>
<div style="display: inline-block">
<div id="checkboxes">
<label><input id="checkboxPO" type="checkbox" value="preventOverlaps" checked/> <code>preventOverlaps</code></label>
<label><input id="checkboxFSE" type="checkbox" value="fastScrollEnd" checked/> <code>fastScrollEnd</code></label>
</div>
</div>
</div>
</section>
<section class="panel move-1 gray"></section>
<section class="panel move-2 gradient-blue"></section>
<section class="panel move-3 gradient-red"></section>
<section class="panel move-4 gradient-green"></section>
<section class="panel move-5 gradient-purple"></section>
<section class="panel spacer gray"></section>
<a name="end"></a>
</div>
<div class="explanation-container">
<div class="explanation">
<div class="tab green">Explanation</div>
<div class="content">
<section class="panel gray">
<div>
<p>Scroll down <strong>slowly</strong> to trigger <i>non-scrubbing</i> animations. Looks great, right? Then try scrolling <i>fast</i> and notice how the animations overlap! </p>
<ul>
<li><code>preventOverlaps: true</code> kicks in when the ScrollTrigger is about to affect its animation (e.g. a toggleAction) - it finds other [prior] ScrollTrigger-based animations and forces them to their end state to avoid overlaps.</li>
<li> <code>fastScrollEnd: true</code> kicks in only when you <strong>LEAVE</strong> the ScrollTrigger's area; it simply says <i>"how fast was the scroll onLeave/onLeaveBack? If it's above the 2500px/second, force the animation to its end immediately"</i>.</li>
</ul>
</div>
</section>
<section class="panel gray">
<div>
<h2>Advanced configuration</h2>
<ul>
<li>If <code>preventOverlaps</code> is a <strong>string</strong>, it acts as a group name so that you can control which ScrollTriggers affect each other's preventOverlaps behavior. It's like setting <code>preventOverlaps: true</code> but only for other ScrollTriggers with the matching string. For example, you could assign <code>preventOverlaps: "group1"</code> (or any arbitrary string) to 3 of your ScrollTriggers so that each of them only prevents overlaps from the other ScrollTriggers that have that same "group1" value.
</li>
<li>If <code>preventOverlaps</code> is a <strong>function</strong>, it'll be called <i>before</i> the non-scrub animation is affected (unlike other callbacks which occur <i>after</i> it's affected), so you can do whatever you want in preparation. All ScrollTriggers have a <code>getTrailing()</code> method you can use to get an Array of all ScrollTriggers that precede this one in the updating order according to the current scroll direction. Use the <code>endAnimation()</code> method to force a ScrollTrigger's animation to jump to its end state according to its direction (so if it's going backwards, it'll <code>.progress(0)</code> if it's forward, it'll <code>.progress(1)</code>).
<pre class="prettyprint">preventOverlaps: (self) => {
self.getTrailing().forEach((trigger) => {
trigger.endAnimation();
});
}</pre>
</li>
<li>If <code>fastScrollEnd</code> is a <strong>number</strong>, it will be interpreted as the velocity threshold in pixels-per-second, like <code>fastScrollEnd: 1000</code> would only activate if the velocity is more than 1000 px/second in either direction when leaving the ScrollTrigger's active area.</li>
</ul>
</div>
</section>
</div>
</div>
</div>
* {
box-sizing: border-box;
}
.panel {
width: 100%;
}
.panel.gray {
background: var(--color-just-black);
}
.jumps {
color: dodgerblue;
z-index: 5;
top: 20px;
left: 50%;
transform: translateX(-50%);
position: fixed;
color: #777;
}
.jumps a {
color: dodgerblue;
}
body {
font-size: 17px;
line-height: 1.4;
font-weight: 300;
overscroll-behavior: none;
}
h1, h2 {
font-weight: 400;
margin-bottom: 2rem;
}
h1 {
font-size: 40px;
}
h1, h2, p, li {
max-width: none;
}
.panel p, .panel li {
font-weight: 300;
}
.panel {
font-weight: 300;
height: auto;
min-height: 100vh;
}
.container {
position: relative;
display: flex;
flex-flow: column;
align-items: center;
}
.pin {
background-color: var(--color-just-black);
min-height: 100vh;
z-index: 1;
display: flex;
flex-direction: column;
width: 94%;
padding: 1rem;
position: fixed;
text-align: center;
}
.standard, .features {
width: 100%;
padding: 1rem;
}
.standard {
border-bottom: 2px solid #555;
}
.features h2 {
margin-bottom: 0;
}
.boxes {
position: relative;
width: 100%;
display: flex;
justify-content: space-between;
}
.box {
width: 5vw;
height: 5vw;
position: relative;
padding: 1%;
border-radius: 10px;
transform: scale(0);
}
#checkboxes {
padding: 12px;
background-color: #111;
text-align: center;
display: flex;
justify-content: space-evenly;
flex-wrap: wrap;
}
#checkboxes input {
width: 20px;
height: 20px;
vertical-align: middle;
}
#checkboxes label {
white-space: nowrap;
margin: 0 14px;
}
.panel p code, .panel li code {
background-color: rgba(0,0,0,0.25);
padding: 2px 6px;
}
.panel li {
margin-bottom: 10px;
}
.box {
background-blend-mode: unset;
}
.box-5 {
visibility: hidden;
}
.explanation {
position: relative;
top: 0;
transform: translateY(-50px);
text-align: center;
max-width: 900px;
margin: 0 auto;
display: inline-block;
/*min-width: 80%;*/
/*left: 50%;*/
}
.explanation-container {
text-align: center;
left: 0;
right: 0;
top: 100vh;
bottom: 0;
position: fixed;
z-index: 100;
overflow: visible;
}
.explanation .tab {
height: 50px;
font-size: 20px;
color: var(--color-just-black);
text-align: center;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
padding: 0 30px;
line-height: 50px;
display: inline-block;
cursor: pointer;
transform: translateY(1px);
border-top: 1px solid #aa70c8;
}
.explanation .content {
overflow: auto;
height: calc(100vh - 65px);
border: 3px solid var(--color-shockingly-green);
border-bottom: none;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
text-align: left;
}
.explanation .panel {
height: auto;
min-height: auto;
padding: 40px;
}
.explanation h2 {
margin: 0;
}
.explanation p, .explanation h2, .explanation ul {
max-width: 800px;
}
.prettyprinted {
overflow: auto;
max-width: 80vw;
}
@media (max-height: 500px) {
.panel h1, .panel h2 {
font-size: 24px;
}
.panel p {
font-size: 17px;
}
#checkboxes input {
width: 12px;
height: 12px;
}
#checkboxes label {
font-size: 14px;
margin: 0 5px;
}
.explanation .tab {
height: 32px;
line-height: 32px;
font-size: 18px;
padding: 0 14px;
}
.explanation {
transform: translateY(-32px);
}
}
gsap.registerPlugin(ScrollTrigger, ScrollToPlugin);
let boxes = gsap.utils.toArray(".boxes"),
checkboxPO = document.querySelector("#checkboxPO"),
checkboxFSE = document.querySelector("#checkboxFSE");
function setup() {
ScrollTrigger.getAll().forEach(t => {t.scroll(0); t.kill(true); });
gsap.set(".box", {
scale: (i, target) => target.classList.contains("box-1") ? 1 : 0
});
boxes.forEach((container, i) => {
let preventOverlaps = i === 1 && checkboxPO.checked && "group1",
fastScrollEnd = i === 1 && checkboxFSE.checked,
box = gsap.utils.toArray(".box", container);
box.pop();
box.forEach((el, i) => {
let tl = gsap.timeline({
scrollTrigger: {
trigger: ".move-" + (i + 2),
start: "top center",
end: "+=100%",
toggleActions: "play none none reverse",
preventOverlaps: preventOverlaps,
fastScrollEnd: fastScrollEnd
}
});
if (i) {
tl.fromTo(el, {scale: 0}, {scale: 1, duration: 0.5, immediateRender: false, ease: "back"}, 0);
}
tl.fromTo(el, {left: "0%"}, {left: "23.75%", duration: 2, immediateRender: false, ease: "power1.inOut"}, i ? "-=0.25" : 0);
tl.to(el, {scale: 0.6, backgroundColor: "#555", duration: 0.5, opacity: 0.5, ease: "power1.in"});
});
});
}
checkboxPO.addEventListener("change", setup);
checkboxFSE.addEventListener("change", setup);
setup();
// explanation tab
let isOpen;
document.querySelector(".explanation .tab").addEventListener("click", () => {
isOpen = !isOpen;
gsap.to(".explanation", {
top: isOpen ? ((window.innerHeight - 65) / window.innerHeight * -100) + "vh" : "0",
ease: "power4",
duration: 0.5
});
});
// jump links
gsap.utils.toArray(".jumps a").forEach((el, i) => {
el.addEventListener("click", e => gsap.to(window, {scrollTo: i ? 0 : "max", overwrite: true}) && e.preventDefault());
});
// making the code pretty/formatted.
PR.prettyPrint();
Also see: Tab Triggers