Pen Settings



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


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


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.


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.


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


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



                var lastState = 0;
var tweeningTo = 0;
var positions = [];
var positionIndex = 0;
var timeScale = 0; 
var updateLast = function(x) {
	lastState = x

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

		tl.add("state0"); // initial state at time 0".red", 1, { x: 100, ease: Power0.easeNone });
      positions.push(tl.duration())".red", 1, { x: 200, ease: Power0.easeNone });
 		positions.push(tl.duration())".red", 1, { x: 300, ease: Power0.easeNone });
		positions.push(tl.duration());".red", 1, { x: 400, ease: Power0.easeNone });
      positions.push(tl.duration());".red", 1, { x: 500, ease: Power0.easeNone });

var states = tl.getLabelsArray()

// Move playhead to appropriate position (based on the index)
	function tweenTo(i) {
      $(".output2").text(i + 1);
		timeScale++; //speed up if user keeps pushing the button.
		positionIndex = i;
		// Tween playhead to new position using a linear ease., Math.abs(positions[i] - tl.time()), {time:positions[i], ease:Linear.easeNone, onComplete:function() {
				// Reset timeScale when tween is done
				timeScale = 0;

$(window).on("keydown", function(e) {
	var keyPressed;
	// go to prev state
	if (e.which == 37) {
		tweenTo(Math.max(positionIndex - 1, 0))
		keyPressed = "&larr;"
	// go to next state
	else if (e.which == 39) {
		tweenTo(Math.min(positionIndex + 1, positions.length-1));
		keyPressed = "&rarr;"
	// debugggg

tl.eventCallback("onUpdate", function() {