Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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="div">
	<div>Use arrow left and right to go back and forth!</div>
	<br />
	<div>Last state completed: <span class="output">x</span></div>
	<div>TweeningTo: <span class="output2">x</span></div>
	<div>timeScale: <span class="output3">x</span></div>
	<br />
	<div>key <span class="output4">x</span> pressed at time <span class="output5">x</span></div>
	<br />
	<div class="boxes">
		<div class="box red"></div>
		<div class="box">1</div>
		<div class="box">2</div>
		<div class="box">3</div>
		<div class="box">4</div>
		<div class="box">5</div>
		<div class="box">6</div>
	</div>
</div>
              
            
!

CSS

              
                
.box {
	z-index: 2;
	position: relative;
	
	width: 100px; height: 100px;
	background: fade(Crimson, 50%);
	
	display: flex;
	justify-content: center;
	align-items: center;
}

.box.red {
	z-index: 1;
	position: absolute; left: 0; top: 0;
	background: Crimson;
	color: white;
}

.boxes {
	position: relative;
	display: flex;
	justify-content: center;
	align-items: center;
}

html,body {
	width: 100%; height: 100%;
	background: #F7E98E; // #9CCDFE;
	overflow: hidden;
}
body {
	display: flex;
	justify-content: center;
	align-items: center;
}


              
            
!

JS

              
                var lastState = 0;
var tweeningTo = 0;

var updateLast = function(x) {
	lastState = x
}

var tl = new TimelineMax({ paused: true })

		.call(updateLast, [0])
		.add("state0") // initial state at time 0
		
		.to(".red", 1, { x: 100, ease: Power0.easeNone })
		.call(updateLast, [1])
		.add("state1")

		.to(".red", 1, { x: 200, ease: Power0.easeNone })
		.call(updateLast, [2])
		.add("state2")

		.to(".red", 1, { x: 300, ease: Power0.easeNone })
		.call(updateLast, [3])
		.add("state3")

		.to(".red", 1, { x: 400, ease: Power0.easeNone })
		.call(updateLast, [4])
		.add("state4")

		.to(".red", 1, { x: 500, ease: Power0.easeNone })
		.call(updateLast, [5])
		.add("state5")


var states = tl.getLabelsArray()

var goTo = function(x) {
	
	// update variable so the events can do their thing
	tweeningTo = x;
	
	// deeebug
	$(".output2").text(tweeningTo)
	
	// tween to the time of the label
	tl.tweenTo( states[tweeningTo].time )
	
	// if there is a skip, increase timeScale
	// timeScale( lastState - x + 1 )
	
	// ideally: duration of timeScale tween as long as 
	// it takes to get to the end of all skipped panels
	// so that the actual last transition can unfold as fast as intended
	if (Math.abs(lastState - tweeningTo) > 1) {
		var factor = 10;
		var newTimeScale = tl.timeScale() * factor;
		TweenMax.fromTo(tl, 1, { timeScale: newTimeScale,  }, { timeScale: 1, ease: Power3.easeIn })
	}
	
}

$(window).on("keydown", function(e) {
	
	var keyPressed;
	
	// go to prev state
	if (e.which == 37) {
		goTo(tweeningTo - 1)
		keyPressed = "&larr;"
		// tl.tweenTo(tl.getLabelBefore())
	}
	
	// go to next state
	else if (e.which == 39) {
		goTo(tweeningTo + 1)
		keyPressed = "&rarr;"
		// tl.tweenTo(tl.getLabelAfter())
	}
	
	// debugggg
	$(".output4").html(keyPressed)
	$(".output5").text(tl.time())
	
})


tl.eventCallback("onUpdate", function() {
	$(".output").text(lastState);
	$(".output3").text(tl.timeScale());
})
              
            
!
999px

Console