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>tl reversed? <span class="output6">x</span></div>
	<div>stored reversed variable? <span class="output7">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 class="box">7</div>
		<div class="box">8</div>
		<div class="box">9</div>
		<div class="box">10</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 timeScale = 0;
var direction = 0;

var reversed = 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", 2, { x: 100, ease: Power0.easeNone })
		.call(updateLast, [1])
		.add("state1")

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

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

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

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

		.to(".red", 2, { x: 600, ease: Power0.easeNone })
		.call(updateLast, [6])
		.add("state6")

		.to(".red", 2, { x: 700, ease: Power0.easeNone })
		.call(updateLast, [7])
		.add("state7")

		.to(".red", 2, { x: 800, ease: Power0.easeNone })
		.call(updateLast, [8])
		.add("state8")

		.to(".red", 2, { x: 900, ease: Power0.easeNone })
		.call(updateLast, [9])
		.add("state9")


var states = tl.getLabelsArray()

var goTo = function(x) {
	
	// cancel and therefore don't increase timeScale
	// if we don't change state
	if (tweeningTo == x) return;

	// update variable so the events can do their thing
	tweeningTo = x;
	
	// comparing the time of the state we want to go
	// and the time at this calling gives negative values for backwards animation
	var duration = states[x].time - tl.time();
	
	reversed = (duration < 0) ? true : false;
	
	timeScale++;
	
	// deeebug
	$(".output3").text(timeScale)
	$(".output2").text(tweeningTo)
	$(".output6").text(tl.reversed())
	$(".output7").text(reversed)
	
	TweenMax.to(tl, Math.abs(duration), { time: states[x].time, ease: Power0.easeNone })
		.timeScale(timeScale)
		.eventCallback("onComplete", function() {
			timeScale = 0;
		})
	
}

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


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

Console