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

              
                <div class="wrapper">
	<div class="box-top"></div>
	<div class="box"></div>
</div>

<!--  WHAT DO I EXPECT? 

First start
1. Orange box appears
2. Red box move
3. Orange box disappear
Now the yoyo return and...
4. Do not repeat reversed step 3
5. Move(reversed) red box
6. Do not repeat reversed step 1
And now the loop starts again
7. go back to 1st step...
-->
              
            
!

CSS

              
                .wrapper {
	max-width: 500px;
	height: 500px;
	margin: 0 auto;
	padding: 100px;
}

.box {
	position: relative;
	width: 150px;
	height: 150px;
	background: red;
}
.box-top {
	width: 50px;
	height: 50px;
	background: orange;
}

              
            
!

JS

              
                const mainTL = gsap.timeline({
	onRepeat: TL_REPEAT,
	yoyo: true,
	repeat: -1,
	repeatDelay: 1
});

if (mainTL.progress() !== 1) {
	// i would like it to skip this on yoyo return
	mainTL.add(MOVE_TOP_BOX_ON_BEGINING());
}

// This should always run
mainTL.add(MOVE_MAIN_BOX());

if (mainTL.progress() === 0) {
	// i would like it to skip this on yoyo begining
	mainTL.add(HIDE_TOP_BOX_ON_COMEBACK());
}

// This should trigger only when timeline starts (yoyo begin) but when timeline goes back it should skip this step and turn around again
function MOVE_TOP_BOX_ON_BEGINING() {
	const top_box = document.querySelector(".box-top");

	const tl = gsap.timeline();
	tl.fromTo(
		top_box,
		{ opacity: 0, x: "-=50" },
		{
			x: 0,
			opacity: 1
		}
	);

	return tl;
}

// HIDE TOP BOX WHEN TIMELINE FINISHED (with repeat&yoyo - progres = 0)
function HIDE_TOP_BOX_ON_COMEBACK() {
	const boxTop = document.querySelector(".box-top");

	const tl = gsap.timeline();
	tl.to(boxTop, {
		y: "+=30",
		opacity: 0,
		duration: 1
	});

	return tl;
}

function MOVE_MAIN_BOX() {
	const box = document.querySelector(".box");

	const tl = gsap.timeline();
	tl.to(box, {
		y: "+=30",
		duration: 1
	});

	return tl;
}

function TL_REPEAT() {
	// const isTimelineGoingBack = mainTL.progress() === 1;
	// if (isTimelineGoingBack) {
	// 	console.log(`🔙 Timeline is going back`);
	// 	HIDE_TOP_BOX_ON_COMEBACK();
	// } else {
	// 	console.log(`🛫 Timeline begin`);
	// }
}

              
            
!
999px

Console