Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!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>

              
            
!

CSS

              
                :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%;
}


              
            
!

JS

              
                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',
});

              
            
!
999px

Console