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.
#mario
.background
.inner
- (1..23).each do
.cloud <span class="mountain"></span>
.intro
%h1 Super Mario Timeline
%p Initial launch dates of games in the Super Mario series.
%ul.timeline
%li
%time{datetime: "1985-09","data-splitting" => "words"}> September 1985
%span{"data-splitting" => "words"} Super Mario Brothers
%li
%time{datetime: "1986-06","data-splitting" => "words"}> June 1986
%span{"data-splitting" => "words"} Super Mario Bros: The Lost Levels
%li
%time{datetime: "1988-10","data-splitting" => "words"}> October 1988
%span{"data-splitting" => "words"} Super Mario Bros. 2
%li
%time{datetime: "1988-10","data-splitting" => "words"}> October 1988
%span{"data-splitting" => "words"} Super Mario Bros. 3
%li
%time{datetime: "1989-04","data-splitting" => "words"}> April 1989
%span{"data-splitting" => "words"} Super Mario Land
%li
%time{datetime: "1990-11","data-splitting" => "words"}> November 1990
%span{"data-splitting" => "words"} Super Mario World
%li
%time{datetime: "1992-10","data-splitting" => "words"}> October 1992
%span{"data-splitting" => "words"} Super Mario Land: 6 Golden Coins
%li
%time{datetime: "1995-08","data-splitting" => "words"}> August 1995
%span{"data-splitting" => "words"} Super Mario World 2: Yoshi's Island
%li
%time{datetime: "1996-06","data-splitting" => "words"}> June 1996
%span{"data-splitting" => "words"} Super Mario 64
%li
%time{datetime: "2002-07","data-splitting" => "words"}> July 2002
%span{"data-splitting" => "words"} Super Mario Sunshine
%li
%time{datetime: "2006-05","data-splitting" => "words"}> May 2006
%span{"data-splitting" => "words"} New Super Mario Bros.
%li
%time{datetime: "2007-11","data-splitting" => "words"}> November 2007
%span{"data-splitting" => "words"} Super Mario Galaxy
%li
%time{datetime: "2009-11","data-splitting" => "words"}> November 2009
%span{"data-splitting" => "words"} New Super Mario Bros. Wii
%li
%time{datetime: "2010-05","data-splitting" => "words"}> May 2010
%span{"data-splitting" => "words"} Super Mario Galaxy 2
%li
%time{datetime: "2011-11","data-splitting" => "words"}> November 2011
%span{"data-splitting" => "words"} Super Mario 3D Land
%li
%time{datetime: "2012-07","data-splitting" => "words"}> July 2012
%span{"data-splitting" => "words"} New Super Mario Bros 2
%li
%time{datetime: "2012-11","data-splitting" => "words"}> November 2012
%span{"data-splitting" => "words"} New Super Mario Bros. U
%li
%time{datetime: "2013-11","data-splitting" => "words"}> November 2013
%span{"data-splitting" => "words"} Super Mario 3D World
%li
%time{datetime: "2015-09","data-splitting" => "words"}> September 2015
%span{"data-splitting" => "words"} Super Mario Maker
%li
%time{datetime: "2016-12","data-splitting" => "words"}> December 2016
%span{"data-splitting" => "words"} Super Mario Run
%li
%time{datetime: "2017-10","data-splitting" => "words"}> October 2017
%span{"data-splitting" => "words"} Super Mario Odyssey
%li
%time{datetime: "2019-06","data-splitting" => "words"}> June 2019
%span{"data-splitting" => "words"} Super Mario Maker 2
%li
%time{datetime: "2021-02","data-splitting" => "words"}> February 2021
%span{"data-splitting" => "words"} Super Mario 3D World + Bowser's Fury
- (1..23).each do
%span.marker
@font-face {
font-family: "Press Start 2P";
font-style: normal;
font-weight: 400;
src: url("https://assets.codepen.io/383755/press-start.woff2") format("woff2");
}
@font-face {
font-family: "Plumbers";
font-style: normal;
font-weight: 400;
src: url("https://assets.codepen.io/383755/SuperPlumberBrothers.woff2")
format("woff2");
}
body {
cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50px' height='50px' viewBox='0 0 50 50' version='1.1'%3E%3Cdefs%3E%3Cstyle%3Epath%7Bstroke-width:0.5 !important; stroke: %23fff !important;%7D.mouse%7Banimation:scroll 1s ease-in-out infinite;%7D@keyframes scroll%7Bto%7Btransform:translateY(5px)%7D%7D%3C/style%3E%3C/defs%3E%3Cpath style=' stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;' d='M 27.640625 31.839844 L 25 34.480469 L 22.359375 31.839844 C 22.039062 31.519531 21.558594 31.519531 21.238281 31.839844 C 20.917969 32.160156 20.917969 32.640625 21.238281 32.960938 L 24.441406 36.160156 C 24.601562 36.320312 24.800781 36.398438 25 36.398438 C 25.199219 36.398438 25.398438 36.320312 25.558594 36.160156 L 28.761719 32.960938 C 29.078125 32.640625 29.078125 32.160156 28.761719 31.839844 C 28.441406 31.519531 27.960938 31.519531 27.640625 31.839844 Z M 27.640625 31.839844 '/%3E%3Cpath style=' stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;' d='M 28.761719 27.441406 C 28.441406 27.121094 27.960938 27.121094 27.640625 27.441406 L 25 30.078125 L 22.359375 27.441406 C 22.039062 27.121094 21.558594 27.121094 21.238281 27.441406 C 20.917969 27.761719 20.917969 28.238281 21.238281 28.558594 L 24.441406 31.761719 C 24.601562 31.921875 24.800781 32 25 32 C 25.199219 32 25.398438 31.921875 25.558594 31.761719 L 28.761719 28.558594 C 29.078125 28.238281 29.078125 27.761719 28.761719 27.441406 Z M 28.761719 27.441406 '/%3E%3Cpath style=' stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;' d='M 32.199219 18 L 32.199219 10.800781 C 32.199219 6.839844 28.960938 3.601562 25 3.601562 C 21.039062 3.601562 17.800781 6.839844 17.800781 10.800781 L 17.800781 18 C 17.800781 21.960938 21.039062 25.199219 25 25.199219 C 28.960938 25.199219 32.199219 21.960938 32.199219 18 Z M 25 23.601562 C 21.921875 23.601562 19.398438 21.078125 19.398438 18 L 19.398438 10.800781 C 19.398438 7.71875 21.921875 5.199219 25 5.199219 C 28.078125 5.199219 30.601562 7.71875 30.601562 10.800781 L 30.601562 18 C 30.601562 21.078125 28.078125 23.601562 25 23.601562 Z M 25 23.601562 '/%3E%3Cpath class='mouse' style=' stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;' d='M 25 8 C 24.558594 8 24.199219 8.359375 24.199219 8.800781 L 24.199219 11.199219 C 24.199219 11.640625 24.558594 12 25 12 C 25.441406 12 25.800781 11.640625 25.800781 11.199219 L 25.800781 8.800781 C 25.800781 8.359375 25.441406 8 25 8 Z M 25 8 '/%3E%3C/svg%3E%0A"),
ns-resize;
image-rendering: pixelated;
--orange: #e45f12;
--yellow: #ffddc6;
--boost: 0px;
--speed: 0.00001;
--jump: -225px;
--flip: 1;
--animation: stand;
--progress: 0;
padding: 0;
margin: 0;
position: relative;
display: block;
height: 2300vh;
overflow-x: hidden;
font-family: "Press Start 2P";
&:after {
content: "SCROLL ";
position: fixed;
color: #000;
width: 12px;
font-size: 12px;
height: 100px;
display: flex;
left: 45px;
top: calc(50vh - 75px);
z-index: 7;
flex-wrap: wrap;
word-break: break-all;
line-height: 1.5;
justify-content: center;
align-items: flex-start;
color: var(--yellow);
animation: scrollme 2s linear infinite;
transform: translateX(
clamp(-100px, calc(50px - (var(--progress) * 100px)), 0px)
);
@keyframes scrollme {
33% {
content: "SCROLL ▼";
}
66% {
content: "SCROLL ▼▼";
}
100% {
content: "SCROLL ▼▼▼";
}
}
}
&:before {
content: "";
position: fixed;
width: 100vw;
height: 100vh;
z-index: 10;
top: 0;
left: 0;
background: url("https://assets.codepen.io/383755/curtain1.png") 0px 100% /
35px auto repeat-x,
url("https://assets.codepen.io/383755/curtain2.png") 0px calc(100% - 10px) /
35px auto;
transition: transform 1.5s ease-in-out 1s;
transform: translateY(0);
}
&.jump {
#mario {
animation: none;
background: url("https://assets.codepen.io/383755/smb1_mario_sheet.gif") -575px -200px/800px
auto no-repeat;
transform: scaleX(var(--flip)) translateZ(0px)
translateY(calc((var(--progress) * var(--jump) + var(--boost))));
}
}
@for $i from 1 through 23 {
&.loaded {
.intro {
transform: translateY(0px);
}
&:before {
transform: translateY(-100%);
}
.timeline {
li {
&:first-of-type {
> span,
time {
span.word {
transition-delay: calc(
(var(--word-index) * 0.02s) + var(--modifier) + 2s
);
transform: translateY(0);
}
}
}
}
}
}
&.coin#{($i - 1)} {
.timeline {
li {
&:nth-of-type(#{$i + 1}) {
> span,
time {
span.word {
transform: translateY(0px);
}
}
}
&:nth-of-type(#{$i}) {
&:before {
background: linear-gradient(to bottom, #8c1000, #8c1000)
50%
50% /
30px
45px
no-repeat,
url(https://assets.codepen.io/383755/items.png) -206px
0px/900px
auto
no-repeat;
animation: bounce 0.05s ease-in-out 2 alternate;
--height: -10px;
@keyframes bounce {
to {
transform: translateY(var(--height));
}
}
}
&:after {
animation: coin 0.5s steps(3, end) infinite 0.15s,
bounce 0.25s ease-in-out 2 alternate;
transform: translateY(-10px);
--height: -125px;
@keyframes coin {
50% {
background-position: -730px -300px;
}
}
}
&:nth-of-type(7) {
&:after {
animation: none;
transform: none;
}
}
&:nth-last-of-type(2) {
&:before {
background: url(https://assets.codepen.io/383755/bowser.gif)
0px
0px /
auto
125px
no-repeat;
animation: bowser 0.5s steps(3, end) infinite;
}
}
&:nth-of-type(3n) {
&:after {
animation: flower 0.5s steps(2, end) infinite 0.15s,
grow 1s ease-in-out 1 forwards;
@keyframes grow {
to {
transform: translate(-1.5px, -60.5px);
}
}
@keyframes flower {
to {
background-position: -207.5px -200px;
}
}
}
}
}
}
}
}
}
span.marker {
position: absolute;
height: 33.33vh;
width: 100vw;
top: 33.33vh;
pointer-events: none;
@for $i from 1 through 23 {
&:nth-of-type(#{$i}) {
top: calc(33.33vh + #{($i - 1) * 100vh});
}
}
}
.intro {
position: fixed;
text-align: center;
top: 0;
left: 0;
padding: 30px 0 10px;
backdrop-filter: blur(4px);
width: 100vw;
background: rgba(255, 255, 255, 0.15);
z-index: 11;
transition: transform 0.75s ease-in-out 0.5s;
transform: translateY(-100%);
h1 {
font-family: "Plumbers";
font-size: clamp(20px, 10vh, 80px);
text-transform: uppercase;
color: var(--yellow);
text-shadow: 0 10px 0 #000;
-webkit-text-stroke: 1px var(--orange);
}
* {
width: 100%;
text-align: center;
margin: 0;
color: var(--yellow);
text-shadow: 0 2px var(--orange);
}
}
}
body.final {
.background {
.inner {
&:after {
opacity: 1;
}
}
}
}
.background {
width: 100vw;
height: 100vh;
position: fixed;
z-index: 0;
left: 0;
top: 0;
&:before {
content: "";
position: absolute;
width: 75px;
height: 75px;
background: url("https://assets.codepen.io/383755/lakitu.png") 50% 50% /
contain no-repeat;
z-index: 9;
top: 125px;
left: 300vw;
transform: translateX(calc(var(--progress) * -5vw)) translateZ(0px);
animation: hover 3s ease-in-out infinite alternate;
@keyframes hover {
to {
transform: translateX(calc((var(--progress) * -5vw) + 300px))
translateZ(0px);
}
}
}
.inner {
--t: rgba(255, 255, 255, 0.0001);
position: absolute;
width: 2300vw;
height: 100vh;
left: 0;
top: 0;
transform-style: preserve-3d;
background: linear-gradient(to right, #5d94fb 100px, var(--t) 100px)
calc(400vw - 50px) 50% / 100% auto,
linear-gradient(to right, #5d94fb 45px, var(--t) 0px) 0% 0% / 100% 100%
no-repeat,
linear-gradient(to bottom, #5d94fb calc(50% + 160px), var(--t) 50%),
url("https://assets.codepen.io/383755/ground.jpg") 50% calc(50% + 35px) /
50px 50px;
transform: translateX(calc(var(--progress) * -22vw)) translateZ(0px);
&:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
background: linear-gradient(
to bottom,
#000 calc(50% + 160px),
var(--t) calc(50% + 160px)
),
url("https://assets.codepen.io/383755/ground.jpg") 50% calc(50% + 35px) /
50px 50px;
filter: saturate(0);
opacity: 0;
z-index: 9;
transition: opacity 0.5s ease-in-out;
}
&:before {
content: "";
opacity: 0.5;
position: absolute;
width: calc(100% - 100vw);
left: 50vw;
background: repeating-linear-gradient(
to right,
var(--yellow) 10px,
var(--t) 10px,
var(--t) 30px,
var(--yellow) 30px,
var(--yellow) 40px
)
0% 50% / calc(var(--progress) * 1%) 50% no-repeat;
height: 7.5px;
bottom: calc(50% + 97.5px);
}
.mountain {
position: absolute;
width: 400px;
height: 400px;
top: -70px;
left: 0;
background: url("https://assets.codepen.io/383755/pngkit_hill-png_9681105.png")
50% 100% / contain no-repeat;
z-index: 3;
&:before {
content: "";
position: absolute;
width: 300px;
height: 400px;
background: inherit;
left: 25vw;
transform: translateX(calc(var(--progress) * 1vw)) translateZ(0px);
}
&:after {
content: "";
position: absolute;
left: -25vw;
height: 75px;
width: 200px;
background: url("https://assets.codepen.io/383755/bush.png") 50% 0% / 100%
auto no-repeat;
top: 325px;
transform: translateX(calc(var(--progress) * 2vw)) translateZ(0px);
}
}
.cloud {
position: absolute;
width: 200px;
height: 100px;
top: calc(50% - 170px);
z-index: 2;
background: url("https://assets.codepen.io/383755/clouds_1.png") 0px 0px /
450px auto no-repeat;
transform: translateX(calc(var(--progress) * 0.5vw)) translateZ(0px);
&:nth-of-type(4) {
.mountain {
display: none;
}
}
&:before,
&:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
left: -35vw;
top: -100px;
background: url("https://assets.codepen.io/383755/clouds_1.png") -10px -105px /
450px auto no-repeat;
transform: translateX(calc(var(--progress) * -2vw)) translateZ(0px);
}
&:after {
left: 25vw;
top: 100px;
transform: translateX(calc(var(--progress) * 2vw)) translateZ(0px);
}
@for $i from 1 through 23 {
&:nth-of-type(#{$i}) {
left: calc(#{$i * 100}vw - 50vw);
}
&:nth-of-type(3n) {
.mountain {
left: -12.5vw;
&:after {
transform: translateX(calc((var(--progress) * 0.5vw)) + 10vw)
translateZ(0px);
}
}
}
&:nth-of-type(even) {
.mountain {
&:before {
left: 50vw;
transform: translateX(calc(var(--progress) * 0.5vw)) translateZ(0px);
}
}
&:before {
top: -125px;
}
&:after {
top: -200px;
transform: translateX(calc(var(--progress) * -0.25vw)) translateZ(0px);
}
}
}
}
}
}
#mario {
z-index: 1;
width: 160px;
height: 160px;
background: url("https://assets.codepen.io/383755/smb1_mario_sheet.gif") 50px -200px /
800px auto no-repeat;
animation: var(--animation)
clamp(0.125s, calc((5 - (var(--speed) / 2000)) * 0.025s), 0.5s)
steps(3, start) infinite;
position: fixed;
left: calc(50% - 80px);
top: calc(50% + 5px);
transform: scaleX(var(--flip)) translateZ(0px);
transform-origin: 90px 50%;
@keyframes run {
from {
background-position: -427.5px -200px;
}
to {
background-position: -75px -200px;
}
}
}
.timeline {
padding: 0;
margin: 0;
z-index: 3;
position: fixed;
width: 2300vw;
height: 100vh;
transform: translateX(calc(var(--progress) * -22vw)) translateZ(0px);
list-style-type: none;
li {
height: 150px;
width: 400px;
display: flex;
align-items: center;
flex-wrap: wrap;
justify-content: center;
text-align: center;
position: absolute;
font-size: 16px;
padding: 2rem;
box-sizing: border-box;
background: linear-gradient(to right, #fff, #fff) 5px 5px / 5px 5px no-repeat,
linear-gradient(to right, #000, #000) 5px 5px / 8px 8px no-repeat,
linear-gradient(to right, #fff, #fff) calc(100% - 5px) 5px / 5px 5px
no-repeat,
linear-gradient(to right, #000, #000) calc(100% - 2px) 5px / 8px 8px
no-repeat,
linear-gradient(to right, #fff, #fff) 5px calc(100% - 5px) / 5px 5px
no-repeat,
linear-gradient(to right, #000, #000) 5px calc(100% - 2px) / 8px 8px
no-repeat,
linear-gradient(to right, #fff, #fff) calc(100% - 5px) calc(100% - 5px) / 5px
5px no-repeat,
linear-gradient(to right, #000, #000) calc(100% - 2px) calc(100% - 2px) / 8px
8px no-repeat,
var(--orange);
bottom: 50%;
z-index: 9;
color: #fcddcc;
box-shadow: -3px 0 0 #fff, 0 -3px 0 #fff, 0 3px 0 #000, 3px 0 0 #000,
-3px 3px 0 #000;
text-shadow: 0 4px 0 #000;
&:nth-of-type(3n) {
&:after {
background: url(https://assets.codepen.io/383755/items.png) 0px -200px/900px
auto no-repeat;
transform: translate(-1.5px, -7.5px);
}
}
&:nth-of-type(7) {
&:after {
background: url(https://assets.codepen.io/383755/pipe.gif) 50% 100% /
contain no-repeat;
width: 300px;
height: 175px;
transform: none;
left: calc(50vw + 50% - 150px);
top: calc(50% + 135px);
clip-path: polygon(0 0, 100% 0, 100% 57.5%, 0 57.5%);
}
&:before {
display: none;
}
}
&:nth-last-of-type(2) {
&:before {
animation: none;
left: calc(50vw + 50% - 42.5px);
background: url(https://assets.codepen.io/383755/bowser.gif) 0px 0px / auto
125px no-repeat;
top: calc(50% + 115px);
height: 125px;
width: 125px;
animation: bowser 0.5s steps(3, end) infinite;
transition: transform 0.5s ease-in-out;
@keyframes bowser {
to {
background-position: -360px 0px;
}
}
}
&:after {
display: none;
}
}
&:last-of-type {
&:before {
animation: none;
left: calc(100% + 85px);
background: url(https://assets.codepen.io/383755/items.png) -825px 0px/900px
auto no-repeat;
top: calc(50% + 151.5px);
}
&:after {
display: none;
}
}
&:before,
&:after {
content: "";
position: absolute;
background: url("https://assets.codepen.io/383755/items.png") 0px 0px / 900px
auto no-repeat;
height: 85px;
width: 85px;
z-index: 9;
left: calc(50vw + 50% - 42.5px);
top: calc(50% - 70px);
animation: flash 1s steps(1, end) infinite;
@keyframes flash {
50% {
background-position: -103px 0px;
}
}
}
&:after {
animation: none;
transform: translateY(-10px);
background: url("https://assets.codepen.io/383755/items.png") -415px -300px/900px
auto no-repeat;
z-index: 8;
left: calc(50vw + 50% - 40px);
}
time,
> span {
position: absolute;
display: flex;
height: 50%;
justify-content: center;
align-items: center;
top: 0%;
line-height: 1;
overflow: hidden;
max-width: 100%;
flex-wrap: wrap;
.word {
display: inline-block;
margin: 0 0.5rem;
transition: transform cubic-bezier(1, 0, 0, 1) 0.75s;
transition-delay: calc((var(--word-index) * 0.02s) + var(--modifier));
}
}
time {
color: #fff;
--modifier: 0.15s;
.word {
transform: translateY(-200px);
}
}
> span {
top: 50%;
align-items: flex-start;
--modifier: 0s;
.word {
transform: translateY(200px);
}
}
@for $i from 1 through 23 {
&:nth-of-type(#{$i}) {
left: calc(#{($i - 1) * 100vw} + (50vw - 200px));
}
}
}
}
body::-webkit-scrollbar {
width: 5px;
}
body::-webkit-scrollbar-track {
background: var(--yellow);
}
body::-webkit-scrollbar-thumb {
background-color: var(--orange);
outline: 1px solid var(--yellow);
}
const mario = document.getElementById("mario");
const body = document.body;
Splitting();
ScrollTrigger.create({
trigger: "body",
start: "top top",
end: "bottom bottom",
scrub: 1,
onUpdate: (self) => {
body.style.setProperty("--progress", self.progress * 100);
if (self.progress > 0.95) {
body.classList.add("final");
mario.style.setProperty("--boost", "-35px");
} else {
body.classList.remove("final");
mario.style.setProperty("--boost", "0px");
}
}
});
gsap.utils.toArray(".marker").forEach((marker, index) => {
gsap.to(this, {
scrollTrigger: {
trigger: marker,
start: "top 0%",
end: "bottom 0%",
scrub: 0,
onUpdate: (self) => {
if (self.progress < 0.5) {
mario.style.setProperty("--progress", self.progress);
} else {
mario.style.setProperty("--progress", 1 - self.progress);
body.classList.add("coin" + index);
}
},
onEnter: () => {
body.classList.add("jump");
},
onEnterBack: () => {
body.classList.add("jump");
},
onLeave: () => {
body.classList.remove("jump");
body.classList.remove("coin" + (index + 1));
},
onLeaveBack: () => {
body.classList.remove("jump");
body.classList.remove("coin" + (index + 1));
}
}
});
});
gsap.to("body", {
opacity: 1,
scrollTrigger: {
trigger: "body",
start: "top top",
end: "bottom bottom",
scrub: 0.05,
onScrubComplete: () => {
mario.style.setProperty("--animation", "stand");
},
onUpdate: ({ getVelocity }) => {
mario.style.setProperty("--animation", "run");
if (getVelocity() < 1) {
mario.style.setProperty("--flip", "-1");
} else {
mario.style.setProperty("--flip", "1");
}
const speed = Math.abs(Math.round(getVelocity()));
mario.style.setProperty("--speed", speed);
}
}
});
document.addEventListener(
"DOMContentLoaded",
function () {
body.classList.add("loaded");
},
false
);
body.addEventListener(
"click",
function () {
body.classList.toggle("loaded");
},
false
);
Also see: Tab Triggers