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 id="hero" class="section">
<h1 class="animate left-to-right fade-in">Simple Scroll animations</h1>
<p class="animate left-to-right fade-in">A simple showcase of what this library can do to help you add animations to your website.</p>
<div class="animate bottom-to-top staggered">
<a href="#side-to-side-showcase" class="button">Take a look!</a>
</div>
</div>
<div id="side-to-side-showcase" class="section">
<h2 class="animate delay200">All cardinal directions!</h2>
<div class="flex-container">
<div class="block animate left-to-right"></div>
<div class="block animate top-to-bottom"></div>
<div class="block animate bottom-to-top"></div>
<div class="block animate right-to-left"></div>
</div>
<div class="animate fade-in delay300 column">
<a href="#cards-showcase" class="button">See more: Cards</a>
<a href="#hero">Go back</a>
</div>
</div>
<div id="cards-showcase" class="section">
<h2 class="animate delay200">Sick staggered cards with one class</h2>
<div class="flex-container">
<div class="block animate left-to-right staggered"></div>
<div class="block animate left-to-right staggered"></div>
<div class="block animate left-to-right staggered"></div>
<div class="block animate left-to-right staggered"></div>
</div>
<div class="animate fade-in delay400 column">
<a href=""></a>
<a href="#delay-showcase" class="button">See more: Setting a delay</a>
<a href="#side-to-side-showcase">Go back</a>
</div>
</div>
<div id="delay-showcase" class="section">
<h2 class="animate">Easily set a delay</h2>
<div class="flex-container delay-grid">
<span class="animate delay100">You</span>
<span class="animate delay500">just</span>
<span class="animate delay300">set</span>
<span class="animate delay200">a</span>
<span class="animate delay700">value</span>
<span class="animate delay600">from</span>
<span class="animate delay900">100</span>
<span class="animate delay400">to</span>
<span class="animate delay1000">1000</span>
</div>
<div class="animate fade-in delay100 column">
<a href="#duration-showcase" class="button">See more: Setting a duration</a>
<a href="#cards-showcase">Go back</a>
</div>
</div>
<div id="duration-showcase" class="section">
<h2 class="animate">Set an animation duration</h2>
<p>Your animation can be as <span class="animate bottom-to-top delay300 duration100">short</span> or as <span class="animate top-to-bottom delay400 duration1000">long</span> as you'd like</p>
<div class="animate fade-in delay100 column">
<a href="#installation" class="button">Installation</a>
<a href="#delay-showcase">Go back</a>
</div>
</div>
<div id="installation" class="section">
<h2 class="animate left-to-right staggered">How do I add this to my website?</h2>
<p class="animate left-to-right staggered">Just copy the following code:</p>
<code class="animate left-to-right staggered">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Michal-Skoula/simple-scroll-animations@master/release/latest/styles.css"> <br> <script defer src="https://cdn.jsdelivr.net/gh/Michal-Skoula/simple-scroll-animations@master/release/latest/script.js"></script>
</code>
<p class="animate left-to-right staggered">Or read more in the README:</p>
<div class="animate bottom-to-top delay400">
<a href="https://github.com/Michal-Skoula/simple-scroll-animations" class="">Github Repo</a>
</div>
<div class="animate fade-in delay100 column">
<a href="https://michal-skoula.github.io/website" class="button">View on a real site (my WIP website)</a>
<a href="#duration-showcase">Go back</a>
</div>
</div>
/**
* CONFIG
* Set the variables to adjust timings
*/
:root {
--reanimate-on-scroll-by-default: 0;
--default-animation-duration: 500ms;
--staggered-step-amount:250ms;
--delay-step-amount: 400ms;
--blur-strength: 3px;
--translate-amount-x: 40%;
--translate-amount-y: 40%;
}
@media(prefers-reduced-motion) {
.animate.show {
transition: none !important;
}
}
.animate {
opacity: 0;
filter: blur(var(--blur-strength));
transition:
transform var(--default-animation-duration) ease-in-out,
opacity var(--default-animation-duration),
filter calc(var(--default-animation-duration) * 2/3);
}
.animate.show,
.animate.show.fade-in {
opacity: 1;
filter: blur(0);
}
.animate.fade-in {
opacity: 0;
filter: blur(var(--blur-strength));
}
.noblur {
filter: blur(0) !important;
}
.animate.bottom-to-top {
transform: translateY(var(--translate-amount-y));
}
.animate.show.bottom-to-top {
transform: translateY(0);
}
.animate.right-to-left {
transform: translateX(var(--translate-amount-x));
}
.animate.show.right-to-left {
transform: translateX(0);
}
.animate.top-to-bottom {
transform: translateY(calc(var(--translate-amount-y) * -1));
}
.animate.show.top-to-bottom {
transform: translateY(0);
}
.animate.left-to-right {
transform: translateX(calc(var(--translate-amount-x) * -1));
}
.animate.show.left-to-right {
transform: translateX(0);
}
.animate.staggered {
transition-delay: calc(var(--delay-step-amount) * var(--index));
}
.animate.delay100, .animate.delay200, .animate.delay300,
.animate.delay400, .animate.delay500, .animate.delay600,
.animate.delay700, .animate.delay800, .animate.delay900,
.animate.delay1000 {
transition-delay: calc(var(--delay-step-amount) * var(--delay));
}
.animate.duration100, .animate.duration200, .animate.duration300,
.animate.duration400, .animate.duration500, .animate.duration600,
.animate.duration700, .animate.duration800, .animate.duration900,
.animate.duration1000 {
transition-duration: calc(var(--staggered-step-amount) * var(--duration));
}
.animate.staggered:nth-child(2) { --index: 1; }
.animate.staggered:nth-child(3) { --index: 2; }
.animate.staggered:nth-child(4) { --index: 3; }
.animate.staggered:nth-child(5) { --index: 4; }
.animate.staggered:nth-child(6) { --index: 5; }
.animate.staggered:nth-child(7) { --index: 6; }
.animate.staggered:nth-child(8) { --index: 7; }
.animate.staggered:nth-child(9) { --index: 8; }
.animate.staggered:nth-child(10) { --index: 9; }
.animate.delay100 { --delay: 1; }
.animate.delay200 { --delay: 2; }
.animate.delay300 { --delay: 3; }
.animate.delay400 { --delay: 4; }
.animate.delay500 { --delay: 5; }
.animate.delay600 { --delay: 6; }
.animate.delay700 { --delay: 7; }
.animate.delay800 { --delay: 8; }
.animate.delay900 { --delay: 9; }
.animate.delay1000 { --delay: 10; }
.animate.duration100 { --duration: 1; }
.animate.duration200 { --duration: 2; }
.animate.duration300 { --duration: 3; }
.animate.duration400 { --duration: 4; }
.animate.duration500 { --duration: 5; }
.animate.duration600 { --duration: 6; }
.animate.duration700 { --duration: 7; }
.animate.duration800 { --duration: 8; }
.animate.duration900 { --duration: 9; }
.animate.duration1000 { --duration: 10; }
/*styles*/
:root:root {
--reanimate-on-scroll-by-default: 1;
--default-animation-duration: 500ms;
--staggered-step-amount:250ms;
--delay-step-amount: 250ms;
--blur-strength: 3px;
--translate-amount-x: 40%;
--translate-amount-y: 40%;
}
* {
box-sizing: border-box;
scroll-behavior: smooth;
}
body {
padding: 0;
margin:0;
font-family: Arial, Helvetica, sans-serif;
background-color: #1e1e1e;
color:#f2f2f2;
display: grid;
width: 100vw;
max-width: 100%;
place-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
}
h2 {
margin-bottom: 64px;
}
p {
font-size: 20px;
}
code {
/* overflow:scroll; */
margin: 0 auto;
}
.column {
flex-direction: column;
display: flex;
}
a:not(.button) {
margin-top:16px;
color: grey;
text-decoration: none;
transition: text-decoration 150ms;
}
a:not(.button):hover {
text-decoration: underline;
}
#duration-showcase span:first-child {
font-size: 40px;
color: lemonchiffon;
}
#duration-showcase span:nth-child(2) {
font-size: 40px;
color: lightskyblue
}
.button {
padding: 16px 32px;
background-color: #f2f2f2;
color: #1e1e1e;
border-radius: 10px;
width: max-content;
text-align: center;
margin:64px auto 0 auto;
display: inline-block;
text-decoration: none;
border: 2px solid #f2f2f2;
transition: color 150ms, background-color 150ms;
}
.button:hover {
background-color: #1e1e1e;
color:#f2f2f2;
}
.hero, .section {
min-height: 100vh;
min-height: 100svh;
align-content: center;
display: grid;
}
.flex-container {
width: 100vw;
max-width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap:32px;
justify-content: center;
}
.block {
width: 100px;
aspect-ratio: 1/1;
background-color:red;
border-radius: 10px;
}
.block:nth-child(1) {
background-color: lightblue;
}
.block:nth-child(2) {
background-color: lightcoral;
}
.block:nth-child(3) {
background-color: lightgreen;
}
.block:nth-child(4) {
background-color: lightseagreen;
}
.delay-grid {
max-width: 400px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.delay-grid span {
font-size: 30px;
justify-content: center;
margin: 0 auto;
}
.delay-grid span:nth-child(1) {
font-family: "Arial";
color: #AEC6CF; /* Light pastel blue */
}
.delay-grid span:nth-child(2) {
font-family: "Courier New";
color: #FFB7CE; /* Light pastel pink */
}
.delay-grid span:nth-child(3) {
font-family: "Georgia";
color: #CFCFC4; /* Light pastel gray */
}
.delay-grid span:nth-child(4) {
font-family: "Helvetica";
color: #FFD1DC; /* Light pastel peach */
}
.delay-grid span:nth-child(5) {
font-family: "Lucida Console";
color: #B4E7B8; /* Light pastel green */
}
.delay-grid span:nth-child(6) {
font-family: "Tahoma";
color: #FFDAC1; /* Light pastel orange */
}
.delay-grid span:nth-child(7) {
font-family: "Times New Roman";
color: #E2F0CB; /* Light pastel lime */
}
.delay-grid span:nth-child(8) {
font-family: "Trebuchet MS";
color: #F3E9D2; /* Light pastel beige */
}
.delay-grid span:nth-child(9) {
font-family: "Verdana";
color: #C4DDED; /* Light pastel sky blue */
}
.delay-grid span:nth-child(10) {
font-family: "Comic Sans MS";
color: #F7D9C4; /* Light */
}
// Check default behaviour for reanimating
const rootElement = document.documentElement;
const reanimate = getComputedStyle(rootElement).getPropertyValue('--reanimate-on-scroll-by-default');
reanimate.trim();
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if(entry.isIntersecting) {
entry.target.classList.add('show')
}
else if(reanimate == 1 && !entry.target.classList.contains('once')) {
entry.target.classList.remove('show')
}
else if(reanimate == 0 && entry.target.classList.contains('always')) {
entry.target.classList.remove('show')
}
else if(reanimate == 0) {}
});
});
const toBeAnimated = document.querySelectorAll('.animate');
toBeAnimated.forEach((element) => {observer.observe(element)});
Also see: Tab Triggers