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

              
                button restart

- var swatches = ['red', 'blue'];
.notes
	h2 Expected Outcome
	p Red block executes a single long tween over the course of Blue block executing its multiple tweens.
	h2 Issue
	p The Blue wont execute any of its tweens following that come after its first tween until the Red block finishes executing it's tween.
	h2 Question
	p Is there a way to have Blue's tweens proceed in sequence *while* the Red tween is progressing? Also note, I eventually want to add a ScrollTrigger to this timeline (see commented out JS code in the gsap.timeline), so is there a way to do this without getting into complex keyframes or multiple timeline?
	
.container
	
	.block.block-red
		p Long Persistent Tween
	.block.block-blue
		p Has Multiple Tweens

              
            
!

CSS

              
                * {
	box-sizing: border-box;
}

html {
	background: #111;
	color: white;
	font-size: 62.5%;
	-webkit-font-smoothing: antialiased; 
}

body {
	font-size: 1.6rem;
	line-height: 1.3;
}

.container {
	width: 100%;
	display: flex;
	// justify-content: center;
	align-items: flex-start;
	flex-flow: column;
	gap: 5vw;
	height: 5000px;
}

.block {
	text-align: center;
	width: 10rem;
	padding: 1rem;
	&-red {
		background: red;
	}
	&-blue {
		background: blue;
	}
}

.notes {
	padding: 2rem;
}

h2 {
	font-size: 2rem;
}
p {
	color: #ddd;
}
              
            
!

JS

              
                console.clear();

let tl = gsap.timeline({
	// scrollTrigger: {
	// 	trigger: ".container",
	// 	pin: true,
	// 	scrub: true,
	// 	markers: true
	// },
	// paused: true
});

let total_duration = 5;

tl
.from('.block', {
	alpha: .25,
	duration: .5,
	stagger: .15
}, .5)

// Expected Outcome: Red block moves over the course of "total_duration".
.to('.block-red', {
	x: (index, target, targets)=> window.innerWidth - target.offsetWidth,
	duration: total_duration,
	ease: "Linear.easeNone"
})

// Expected Outcome: While the Red block is move then rest of the timeline process with the Blue block executing multiple tweens with any stops

.to('.block-blue', {
	x: (index, target, targets)=> (window.innerWidth - target.offsetWidth)*.25,
	yPercent: 150,
	duration: total_duration/4,
	ease: "Power4.easeInOut"
}, '<')
.to('.block-blue p', {
	scale: 2,
	color: "cyan",
	ease: "Power4.easeInOut"
}, '<')

.to('.block-blue', {
	x: (index, target, targets)=> (window.innerWidth - target.offsetWidth)*.5,
	yPercent: 0,
	duration: total_duration/4,
	ease: "Power4.easeInOut"
}, ">")
.to('.block-blue p', {
	scale: 1,
	color: "white",
	ease: "Power4.easeInOut"
}, '<')

.to('.block-blue', {
	x: (index, target, targets)=> (window.innerWidth - target.offsetWidth)*.75,
	yPercent: 150,
	duration: total_duration/4,
	ease: "Power4.easeInOut"
}, ">")
.to('.block-blue p', {
	scale: 2,
	color: "yellow",
	ease: "Power4.easeInOut"
}, '<')

.to('.block-blue', {
	x: (index, target, targets)=> (window.innerWidth - target.offsetWidth),
	yPercent: 0,
	duration: total_duration/4,
	ease: "Power4.easeInOut"
}, ">")
.to('.block-blue p', {
	scale: 1,
	color: "white",
	ease: "Power4.easeInOut"
}, '<')


document.querySelector('button').addEventListener('click', ()=> tl.play(0))
              
            
!
999px

Console