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

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 id="gs-ctrl">
	
	<div id="gs-buttons">
		<div class="play">
			<button id="resume">Play</button>
			<button id="pause">Pause</button>
			<button id="restart">Restart</button>
		</div>

		<div class="seek">
			<button id="prev">Prev</button>
			<button id="next">Next</button>
		</div>

		<div class="">
			
		</div>
	</div>

	<div id="gs-timeline">
		<span id="gs-playhead"></span>
	</div>
	
	<div id="gs-labels">
		
	</div>
	
</div>


<script type="text/javascript">
// <![CDATA[

window.Controller =
{
	// properties
		tl			:null,
		paused		:false,
		offsetX		:0,
	
	// elements
		$element	:null,
		$buttons	:null,
		$timeline	:null,
		$playhead	:null,
		$labels		:null,
		
	// instantiation
		init: function(tl, parent)
		{
			// properties
				this.tl			= tl;
				
			// wire update if not already assigned
				if ( ! this.tl.vars.onUpdate )
				{
					this.tl.eventCallback('onUpdate', this.update, null, this);
				}			
				
			// elements
				this.$element	= $('#gs-ctrl');
				this.$buttons	= $('#gs-buttons');
				this.$timeline	= $('#gs-timeline');
				this.$playhead	= $('#gs-playhead');
				this.$labels	= $('#gs-labels');
				
			// handlers
				this.$buttons
					.find('.play button')
					.on('click', $.proxy(this.onPlayButtonsClick, this));
					
				this.$buttons
					.find('.seek button')
					.on('click', $.proxy(this.onSeekButtonsClick, this));
					
				this.$timeline
					.on('mousedown', $.proxy(this.onTimelineMouseDown, this));
					
				this.$labels
					.on('click', 'span', $.proxy(this.onLabelClick, this));
					
			// append to
				this.appendTo(parent);
				
			// refresh
				this.refresh();
		},
		
	// public methods
		refresh:function()
		{
			/* seeking */
				if (this.tl.getLabelsArray)
				{
					/* variables */
						var name, time, value, html;
						var labels = this.tl.getLabelsArray();
						
					/* update labels */
						this.$labels.empty();
						for(var i = 0; i < labels.length; i++){
							name	= labels[i].name;
							time	= labels[i].time;
							value	= Math.floor((time / this.tl.duration()) * 100);
							html	= '<span style="left:' +value+ '%">' +name+ '</span>';
							this.$labels.append(html);
						}
				}
				
			// ui
				this.$buttons.find('.seek')[!!this.tl.getLabelsArray ? 'show' : 'hide']();
			
			// update	
				this.update();
		},
		
		appendTo:function(parent)
		{
			$(parent).append(this.$element);
		},
		
		seek:function(time, pause)
		{
			this.tl.seek(time);
			if (pause)
			{
				this.tl.pause();
			}
			this.update();
		},
		
		update:function()
		{
			if (this.tl)
			{
				var p = this.tl.progress();
				var t = this.tl.time();
				var d = this.tl.duration();
				var c = d * p;
				this.$playhead
					.width((p * 100) + '%')
					.html('Time:&nbsp;' + t.toFixed(3));
            console.log(t);
			}
		},
		
	// internal handlers
		onPlayButtonsClick:function(event)
		{
			this.tl[event.target.id]();
		},
		
		onSeekButtonsClick:function(event)
		{
			var t = event.target.id == 'prev'
				? this.tl.getLabelBefore() || 0
				: this.tl.getLabelAfter() || this.tl.duration();
			this.seek(t);
		},
		
		onTimelineMouseDown:function(event)
		{
			// cancel default event
				event.originalEvent.preventDefault();
				
			// update properties
				this.offsetX = event.pageX - event.offsetX;
				this.paused = this.tl.paused();
				
			// assign event handlers
				$('document')
					.on('mousemove', $.proxy(this.onTimelineMouseMove, this))
					.on('mouseup', $.proxy(this.onTimelineMouseUp, this));
					
			// update
				this.onTimelineMouseMove(event);
		},
		
		onTimelineMouseMove:function(event)
		{
			var w = this.$timeline.width();
			var x = event.pageX - this.offsetX;
			var p = x / w;
			var t = this.tl.totalDuration() * p;
			this.seek(t, true);
		},
		
		onTimelineMouseUp:function(event)
		{
			$('document').off('mousemove mouseup');
			if ( ! this.paused )
			{
				this.tl.resume();
			}
		},
		
		onLabelClick:function(event)
		{
			this.seek($(event.target).text());
		}
}

// ]]>
</script>


<style type="text/css">
button {
	/*background:#EEE;
  border:1px solid #777;*/
}
  
#gs-ctrl > *{
	position: relative;
	width:100%;
	background-color:#ccc;
	margin-top:3px;
}

#gs-ctrl *{
	cursor:default;
	font-size:11px;
}
  
#gs-buttons{
  background-color:transparent;
  margin:0 0 6px 0;
}

#gs-buttons *{
	display:inline-block;
	vertical-align:middle;
	}

#gs-buttons button {
	padding:3px 6px;
}

#gs-timeline{
	background:#444;
  border:1px solid #666;
  border-radius:3px;
   /*box-shadow: inset 0 4px 4px rgba(0,0,0,0.2),inset 0 -4px 4px rgba(0,0,0,0.23);*/
}
  
#gs-timeline span{
	display:block;
	height:30px;
	line-height: 30px;
	text-indent:15px;
	width:50%;
	background:rgba(255, 165, 0, 0.9);
	color:#000;
  border-top-left-radius: 3px;
  border-bottom-left-radius: 3px;
}

#gs-labels{
}

#gs-labels span{
	position: absolute;
	border-left:1px solid red;
	padding:2px;
	margin-left:-1px;
	color:#222;
	font-size:9px;
	font-weight:bold;
	text-transform: uppercase;
	cursor:pointer;
	}

/* Jonathan Marzullo - added CSS styles for buttons and progress bar */
#gs-buttons button {
  font-family:Helvetica, Arial;
	display: block;
	font-size: 12px;
	font-weight: bold;
	padding: 5px 18px 3px;
	margin: 10px 8px 10px 0;
	color: #DDD;
	background-color: #555;
	background: -webkit-linear-gradient(#999, #555);
	background: linear-gradient(#999, #555);
	border: 1px solid rgba(68,68,68,0.8);
	border-radius: 3px;
	text-shadow: 1px 1px 1px #444, -1px -1px 1px #444;
	box-shadow: 0 1px 0 #666, 
              0px 6px 0 #444,
              0 6px 6px rgba(0,0,0,0.6);
	cursor: pointer;
  position:relative;
  float:left;
}
	
#gs-buttons button:active {
  cursor:pointer;
  top:2px;
	color: #fff;
  border: 1px solid rgba(68,68,68,0.8);
	text-shadow: 0 -1px 0 #444, 0 0 2px #ffd, 0 0 53px #fff;
	box-shadow: 0 1px 0 #666, 
              0 2px 0 #444, 
              0 2px 2px rgba(0,0,0,0.9);
	transform: translateY(3px);
}

#gs-buttons button:hover{
  
}
  
#gs-buttons button#prev {
  padding-left:25px;
  padding-right:10px;
}
  
#gs-buttons button#next {
  padding-right:25px;
  padding-left:10px;
}
  
#gs-buttons button:before{
  font-size:18px;
  margin:0;
  padding:0;
  line-height: 0.7em;
  position:relative;
}
  
#gs-buttons button#next:before{
  float:right;
  position:absolute;
  top:5px;
  right:10px;
  content:"\00bb";
}
  
#gs-buttons button#prev:before{
  float:left;
  position:absolute;
  top:5px;
  left:10px;
  content:"\00ab";
}
</style>
<!--
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/56901/timeline-controller_1.js"></script>
-->
              
            
!

CSS

              
                body{
  zoom:2;
}

body:before{
	font-family:"Arial";
	font-size:12px;
	content:"This is a CodePen widget for GSAP animations, and is designed only to be included in other pens. See info for details.";
}

              
            
!

JS

              
                
              
            
!
999px

Console