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.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>sample</title>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Caveat&display=swap" rel="stylesheet">
</head>
<body>
<div class="loading-container" id="loading-container">
<img src="src/topleftcl.png" alt="Cloud 1" class="cloud top-left">
<img src="src/toprightcl.png" alt="Cloud 2" class="cloud top-right">
<img src="src/btmlftcl.png" alt="Cloud 3" class="cloud bottom-left">
<img src="src/btmrightcl.png" alt="Cloud 4" class="cloud bottom-right">
</div>
<div class="main-container" id="container" style="display: none;">
<div class="left-container">
<div class="image-wrapper">
<picture>
<source id="animation-frame-webp" type="image/webp">
<img id="animation-frame" alt="Animation Frame" loading="lazy">
</picture>
<div class="watermark">Sea</div>
<div class="overlay"></div>
</div>
</div>
<div class="right-container">
<img src="src/title.png" alt="Title Image" class="title-image">
<img src="src/sub.png" alt="Sub Image" class="sub-image">
<div class="sub-text">
<p>“SEA</p>
<p>This creative endeavor sets the stage for a world rich in collectibles, toys, animations, and storytelling.</p>
</div>
<img src="src/banner.png" alt="Banner Image" class="banner-image">
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/ScrollTrigger.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/ScrollToPlugin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.7.4/lottie.min.js"></script>
<script src="src/animation.js"></script>
<script src="src/index.js"></script>
</body>
</html>
body, html {
margin: 0;
padding: 0;
overflow-x: hidden;
font-family: Arial, sans-serif;
height: 200%;
background-color: #010cae;
scroll-behavior: smooth;
}
.loading-container {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #010cae;
z-index: 10;
}
.cloud {
position: absolute;
width: 110%;
transition: transform 30s ease-out;
}
.top-left {
top: 0;
left: 0;
}
.top-right {
top: 0;
right: 0;
}
.bottom-left {
bottom: 0;
left: 0;
}
.bottom-right {
bottom: 0;
right: 0;
}
.main-container {
display: flex;
width: 100%;
height: 100vh;
padding: 20px;
position: relative;
}
.left-container, .right-container {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.image-wrapper {
position: relative;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
z-index: 20;
}
.image-wrapper img,
.image-wrapper source {
display: block;
max-width: 650px;
height: auto;
object-fit: contain;
pointer-events: none;
-webkit-user-drag: none;
}
.image-wrapper .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: transparent;
pointer-events: none;
}
.image-wrapper .watermark {
display: none;
position: absolute;
bottom: 10px;
right: 10px;
font-size: 24px;
color: rgba(255, 255, 255, 0.5);
pointer-events: none;
}
.title-image,
.sub-image,
.sub-text,
.banner-image {
position: fixed;
width: 60%;
margin-left: -20%;
top: 200%;
}
.title-image {
top: 110%;
margin-bottom: 5px;
z-index: 10;
}
.sub-image {
top: 120%;
margin-bottom: 5px;
z-index: 10;
}
.sub-text {
top: 130%;
max-width: 40%;
color: rgb(222, 234, 255);
text-align: justify;
font-size: 24px;
font-family: 'Caveat', cursive;
margin-bottom: 10px;
z-index: 10;
}
.banner-image {
top: 140%;
max-width: 43%;
margin-bottom: 10px;
z-index: 10;
}
@media (max-width: 768px) {
.main-container {
flex-direction: column;
}
.left-container, .right-container {
height: 50vh;
}
.image-wrapper img,
.image-wrapper source,
.title-image,
.sub-image,
.sub-text,
.banner-image {
width: 90%;
left: 5%;
}
}
@media (max-width: 480px) {
.main-container {
flex-direction: column;
}
.left-container, .right-container {
height: 50vh;
}
.image-wrapper img,
.image-wrapper source,
.title-image,
.sub-image,
.sub-text,
.banner-image {
width: 100%;
left: 0;
}
}
document.addEventListener("DOMContentLoaded", () => {
// Scroll to the top of the page when it loads or refreshes
window.scrollTo(0, 0);
const frameCount = 150; // Number of images in the sequence
const initialFrames = 75; // Number of initial frames to preload
const images = [];
const imageElement = document.getElementById("animation-frame");
const imageElementWebP = document.getElementById("animation-frame-webp");
const loadingContainer = document.getElementById("loading-container");
const container = document.getElementById("container");
const titleImage = document.querySelector(".title-image");
const subImage = document.querySelector(".sub-image");
const subText = document.querySelector(".sub-text");
const bannerImage = document.querySelector(".banner-image");
let initialFramesLoaded = false;
// Preload images
const preloadImages = () => {
let loadedImages = 0;
for (let i = 301; i <= 450; i++) {
const imgWebP = new Image();
imgWebP.src = `src/optimized/SBS_Play_Skateboard_${i.toString().padStart(4, '0')}.webp`;
imgWebP.loading = i <= 301 + initialFrames - 1 ? 'eager' : 'lazy';
imgWebP.onload = () => {
loadedImages++;
if (loadedImages === initialFrames && !initialFramesLoaded) {
// Initial frames are loaded
initialFramesLoaded = true;
gsap.to(clouds, { opacity: 0, duration: 1 });
}
};
imgWebP.onerror = () => {
console.error(`Failed to load image ${imgWebP.src}`);
loadedImages++;
if (loadedImages === initialFrames && !initialFramesLoaded) {
initialFramesLoaded = true;
gsap.to(clouds, { opacity: 0, duration: 1 });
}
};
images.push(imgWebP);
}
};
// Ensure the loading animation is visible before starting to preload images
loadingContainer.style.display = 'flex';
container.style.display = 'none';
preloadImages();
const initAnimation = () => {
gsap.registerPlugin(ScrollTrigger, ScrollToPlugin);
const updateAnimation = (progress) => {
const frameIndex = Math.floor(progress * (frameCount - 1));
imageElement.src = images[frameIndex].src;
imageElementWebP.srcset = images[frameIndex].src;
};
const totalScrollDistance = document.body.scrollHeight - window.innerHeight;
gsap.to({}, {
scrollTrigger: {
trigger: ".main-container",
start: "top top",
end: `+=${totalScrollDistance}`,
scrub: 1.5, // Set scrub to a higher value for smoother and more controlled scroll
pin: true,
anticipatePin: 1,
snap: {
snapTo: 1 / frameCount, // Snap to the closest frame
duration: { min: 0.2, max: 0.5 }, // Adjust the snapping speed
ease: "power3.inOut" // Ease for snapping
},
onUpdate: self => {
const progress = self.progress;
requestAnimationFrame(() => updateAnimation(progress));
}
}
});
gsap.to(titleImage, {
y: "-250vh", // Move title image up out of the viewport
ease: "none",
scrollTrigger: {
trigger: ".main-container",
start: "top top+=100", // Start slightly after the user begins scrolling
end: `+=${totalScrollDistance / 1}`,
scrub: true
}
});
gsap.to(subImage, {
y: "-250vh", // Move sub image up out of the viewport
ease: "none",
scrollTrigger: {
trigger: ".main-container",
start: "top top+=100", // Start slightly after the user begins scrolling
end: `+=${totalScrollDistance / 1}`,
scrub: true
}
});
gsap.to(subText, {
y: "-250vh", // Move sub text up out of the viewport
ease: "none",
scrollTrigger: {
trigger: ".main-container",
start: "top top+=100", // Start slightly after the user begins scrolling
end: `+=${totalScrollDistance / 1}`,
scrub: true
}
});
gsap.to(bannerImage, {
y: "-250vh", // Move banner image up out of the viewport
ease: "none",
scrollTrigger: {
trigger: ".main-container",
start: "top top+=100", // Start slightly after the user begins scrolling
end: `+=${totalScrollDistance / 1}`,
scrub: true
}
});
};
// Animate clouds on scroll
gsap.registerPlugin(ScrollTrigger);
const cloudAnimation = gsap.timeline({
scrollTrigger: {
trigger: ".loading-container",
start: "top top",
end: "bottom top",
scrub: true,
onUpdate: self => {
if (initialFramesLoaded) {
gsap.to(".cloud", { autoAlpha: 0, ease: "power1.inOut" });
}
},
onEnter: () => {
loadingContainer.style.display = 'none';
container.style.display = 'flex';
initAnimation();
}
}
});
cloudAnimation
.to(".top-left", { duration: 15, x: "-50%", y: "-50%", scale: 2, ease: "power3.inOut" })
.to(".top-right", { duration: 15, x: "50%", y: "-50%", scale: 2, ease: "power3.inOut" }, 0)
.to(".bottom-left", { duration: 15, x: "-50%", y: "50%", scale: 2, ease: "power3.inOut" }, 0)
.to(".bottom-right", { duration: 15, x: "50%", y: "50%", scale: 2, ease: "power3.inOut" }, 0)
.to(".top-left", { duration: 15, x: "-100%", y: "-100%", scale: 4, ease: "power3.inOut" })
.to(".top-right", { duration: 15, x: "100%", y: "-100%", scale: 4, ease: "power3.inOut" }, 15)
.to(".bottom-left", { duration: 15, x: "-100%", y: "100%", scale: 4, ease: "power3.inOut" }, 15)
.to(".bottom-right", { duration: 15, x: "100%", y: "100%", scale: 4, ease: "power3.inOut" }, 15)
.to(".top-left", { duration: 15, x: "-150%", y: "-150%", scale: 6, ease: "power3.inOut" })
.to(".top-right", { duration: 15, x: "150%", y: "-150%", scale: 6, ease: "power3.inOut" }, 30)
.to(".bottom-left", { duration: 15, x: "-150%", y: "150%", scale: 6, ease: "power3.inOut" }, 30)
.to(".bottom-right", { duration: 15, x: "150%", y: "150%", scale: 6, ease: "power3.inOut" }, 30);
});
// Ensure scroll position is reset to the top before the page unloads (refresh or navigate away)
window.addEventListener("beforeunload", () => {
window.scrollTo(0, 0);
});
Also see: Tab Triggers