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 http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Question GSAP</title>
<!-- Custom Stylesheet -->
<link rel="stylesheet" href="style.css" />
<!-- GSAP -->
<script
defer
src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/gsap.min.js"
integrity="sha512-cOH8ndwGgPo+K7pTvMrqYbmI8u8k6Sho3js0gOqVWTmQMlLIi6TbqGWRTpf1ga8ci9H3iPsvDLr4X7xwhC/+DQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"></script>
<script
defer
src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.5/ScrollTrigger.min.js"
integrity="sha512-AMl4wfwAmDM1lsQvVBBRHYENn1FR8cfOTpt8QVbb/P55mYOdahHD4LmHM1W55pNe3j/3od8ELzPf/8eNkkjISQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"></script>
<!-- Custom JS -->
<script defer src="app.js" type="module"></script>
</head>
<body>
<main>
<section class="section__spacer">
<h1>Spacer</h1>
<p>I am making an animation sequence. It is working, but when I add ScrollTrigger to the sequence, the highlight scrollTrigger is triggered automatically when I enter the page</p>
<p>I want the 2nd sequence including the highlight will ONLY appear when the 1st sequene is done</p>
<p>Now when I enter the 2nd sequence, the words are highlighted</p>
<p>What is the best approach to this?</p>
</section>
<!-- Animation -->
<section class="animation">
<div class="container--main">
<div class="container--inner">
<div class="animation__first-sequence">
<div class="circle"></div>
<div class="greeting--container">
<h1 class="greeting"><span class="name__1st">1</span> <span class="name__2nd">2</span> <span class="name__3rd">3</span></h1>
</div>
</div>
<div class="animation__main">
<div class="animation__img--container">
<!-- <img class="animation__img" src="test-img.jpg" alt="Photo" /> -->
<img class="animation__img" src="https://i.ibb.co/TLmZSXP/test-img.jpg" alt="test-img" border="0">
</div>
<div class="animation__text--container">
<p class="p1">
Lorem ipsum dolor sit amet consectetur adipisicing elit. A aperiam corporis quos enim, provident omnis nesciunt suscipit exercitationem, reiciendis fugiat ducimus
illum illo optio eveniet nulla impedit quo ipsam totam.
</p>
<p class="p2">
<span class="highlight"> Lorem ipsum dolor sit amet consectetur adipisicing elit.</span> Velit, similique. Sequi modi vitae eos provident possimus,
<span class="highlight">tempore voluptatum hic</span>, illo neque labore architecto, velit accusamus esse earum adipisci voluptatibus at! Ipsa asperiores dicta
laboriosam fuga suscipit corporis quas, illo itaque possimus sequi placeat maiores velit? Deleniti quae natus optio, quod,
<span class="highlight">illo ipsam vero odit nisi facilis iusto id</span>. Vitae, dolorem? Corrupti hic modi odio inventore ab vel corporis, amet dicta eligendi
quidem veritatis debitis? Velit, commodi obcaecati,
<span class="highlight">ipsam dolorem fuga aut perferendis fugit laboriosam quae quis ipsa voluptas nisi laudantium.</span>
</p>
</div>
</div>
</div>
</div>
</section>
<section class="section__spacer">
<h1>Spacer</h1>
<!-- <img src="https://i.ibb.co/TLmZSXP/test-img.jpg" alt="test-img" border="0"> -->
</section>
</main>
</body>
</html>
:root {
--transition-speed-normal: .5s;
--transition-timing-function-cubic: cubic-bezier(.55, 0, .1, 1);
--animation-speed-slow: 1.6s;
}
body {
color: #fff;
min-height: 100vh;
background-color: #000;
font-family: system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Open Sans, Helvetica Neue, sans-serif;
font-weight: 400;
}
.container--main {
width: 90%;
max-width: 1200px;
margin-inline: auto;
position: relative;
}
.container--inner {
width: 86%;
max-width: 800px;
margin-inline: auto;
}
.section__spacer {
height: 100vh;
text-align: center;
place-content: center;
display: grid;
}
.section__spacer h1 {
font-size: 4rem;
}
.animation {
width: 100%;
min-height: 100vh;
isolation: isolate;
z-index: 9;
background: #000;
position: relative;
overflow: hidden;
}
.animation h1 {
color: #fff;
text-align: center;
font-size: 3rem;
}
.animation .circle {
width: 500px;
height: 500px;
z-index: -1;
background: radial-gradient(circle, #000 0%, #5743b6 100%);
border-radius: 50%;
margin-inline: auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.animation__first-sequence {
width: 100%;
}
.animation .greeting--container {
width: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.animation__main {
padding: 1em;
}
.animation__img--container {
margin-block-end: 2em;
}
.animation__img {
border-radius: var(--border-radius-300);
max-height: 400px;
width: 100%;
object-fit: cover;
pointer-events: none;
}
.animation .p1, .animation .p2 {
font-size: var(--fs-300);
line-height: 2;
}
.animation .p1 {
margin-block-end: 2em;
}
.animation .highlight {
transition: background-size var(--transition-speed-normal) var(--transition-timing-function-cubic), color var(--transition-speed-normal) var(--transition-timing-function-cubic), font-weight var(--transition-speed-normal) var(--transition-timing-function-cubic);
background: linear-gradient(45deg, #c3bd22 0%, #fd2db1 100%) 0 0 / 0% 100% no-repeat;
}
.animation .highlight.active {
color: #000;
background-size: 100% 100%;
}
gsap.registerPlugin(ScrollTrigger);
const intro = () => {
const tl = gsap.timeline({
defaults: {
duration: 3,
ease: 'expo.inOut',
},
});
gsap.set('.greeting span', { display: 'inline-block' });
tl.fromTo('.animation .circle', { y: '-140%' }, { y: '0%', scale: 2, background: 'radial-gradient(circle, hsla(0, 0%, 0%, 1) 50%, hsla(250, 46%, 49%, 1) 100%)' })
.fromTo('.greeting .name__1st', { autoAlpha: 0, x: '-100%' }, { autoAlpha: 1, x: '0%' }, '<1')
.fromTo('.greeting .name__2nd', { autoAlpha: 0, x: '-50%' }, { autoAlpha: 1, x: '0%' }, '<1')
.fromTo('.greeting .name__3rd', { autoAlpha: 0, x: '-30%' }, { autoAlpha: 1, x: '0%' }, '<1')
.to('.greeting--container', { scale: 4.3, autoAlpha: 0, display: 'none' })
.to('.animation .circle', { scale: 2, background: 'radial-gradient(circle, hsla(0, 0%, 0%, 1) 100%, hsla(250, 46%, 49%, 1) 100%)' }, '<1')
.to('.animation__first-sequence', { display: 'none' });
return tl;
};
const second = () => {
const tl = gsap.timeline({
defaults: {
duration: 3,
ease: 'expo.inOut',
},
});
tl.fromTo('.animation__main', { autoAlpha: 0 }, { autoAlpha: 1 });
return tl;
};
const master = gsap.timeline();
master.add(intro()).add(second());
const highlights = [...document.querySelectorAll('.highlight')];
highlights.forEach((el) => {
ScrollTrigger.create({
trigger: el,
start: 'top center',
id: 'highlight',
onEnter: () => {
el.classList.add('active');
},
markers: true,
});
});
// You can remove the ScrollTrigger comment it out
ScrollTrigger.create({
trigger: '.animation',
scrub: true,
id: 'main-animation',
markers: true,
pin: true,
animation: master,
end: '+=2000px',
});
Also see: Tab Triggers