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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

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

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

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.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                <body><div id="bannerHome"></div></body>
              
            
!

CSS

              
                 .gssLayer {position:absolute; overflow:hidden; width:100%; height:100%; left:0; top:0;}
#bannerHome {
  position:absolute;
  width:500px;
  overflow:hidden;
}
              
            
!

JS

              
                
function gssLayout(obj) {
	this.container = obj  //cache some info
	this.w = obj.width()
	this.h = obj.height()
	this.id = obj.attr('id')
	this.layerCount = 0

	this.next = function(tl,delay,trans1,time1,trans2,time2,offset) { //function for creating layers and animating their swapping
		var layer = this.id+'-layer-'+ ++this.layerCount,
        oo = $('#'+layer)
			layer = (oo.length >0) ? oo : $('<div id="'+layer+'" class="gssLayer" />').appendTo(this.container) //if old layer exists, use that, otherwise append new layer
      
		if (this.layerCount !== 1) layer.css('visibility','hidden') //only first visible
		TweenMax.set(layer, {perspective:500})
		if (time1 === 0) time1 = 0.001 //simpler than messing with the rendering mode. Let users pop layers in and out instantly if they wish.
    if (time2 === 0) time2 = 0.001 //I still think TweenMax.to() should default to immediateRender:false despite the duration used, so this is my silent protest against an illogical convention. 
		if (typeof tl === 'object') { //tl == timeline
			if (typeof trans1 === 'undefined') tl.hide(this.layer,'+='+delay).show(layer) //stop here if no transitions defined, and swap layers
			else {
				var trans = [trans1,trans2],
					style = [{ease:Linear.easeNone},{ease:Linear.easeNone}],
					i = 1 // put arguements and tween objects into arrays
				do { //fill 'style' objects with tween properties based on 'trans' arguements
					var t = trans[i].split(' '), s = style[i]
					for (var c = 0; c < t.length; c++) {
						switch(t[c]) {
              case 'right':
                s.left = this.w
                break
							case 'left':
								s.left = this.w*-1
								break
							case 'spin':
								s.rotation = -720
								s.ease = Power4.easeOut
								break
						}
					}
					style[i] = s
				} while (i--)
				if (offset) offset = '+='+ offset //format offset, if it exists
				tl.to(this.layer,time1,style[0],'+='+delay).hide(this.layer) //animate out old layer, then hide it
					.show(layer,offset).from(layer,time2,style[1],offset) //make visible, then animate in new layer
			}
		}
    return this.layer = layer
	}
	this.next()//create first layer

	this.size = function(width,height,callback,tl){ //function to resize the animation and rebuild it
		var t = this, w = width || t.container.width(), h = height || t.container.height()
		if (typeof w === 'string') { //format size ratio arguements if given for width
			var w = width.split('/')
			if (w.length >1) w = Math.floor(w[0] * h / w[1])
		}
		if (typeof h === 'string') { //same for height
			var h = height.split('/')
			if (h.length >1) h = Math.floor(h[1] * w / h[0])
		}
		if (width) t.container.css('width',w) //change dimensions if given, leave alone if passed false/0
		if (height) t.container.css('height',h)
    t.w = w //cache measurements
		t.h = h
		if (callback) {
			if (tl) { tl.seek(0).clear() }  //empty the timeline
			t.layerCount = 0  //reset layer counter, so new layers aren't created
			$('[id^='+ t.id +'-]').attr('style','') //remove old style attributes, so animations are cleared
			t.next() //make first layer available
			callback() //call timeline creation function
		}
	}
}
TimelineMax.prototype.show = function(obj,offset) { //convenience shortcuts
	this.set(obj,{visibility:'visible'},offset)
	return this
}
TimelineMax.prototype.hide = function(obj,offset) {
	this.set(obj,{visibility:'hidden'},offset)
	return this
}

var banner = $('#bannerHome'),
  b = new gssLayout(banner), //initialize
  tl = new TimelineMax({repeat:-1})

b.size(0,'7/3',bannerMake,tl) //set ratio size based on current width

setTimeout(function(){ b.size(700,'7/3',bannerMake,tl) }, 5*1000)  //change size based on new width, setting height with ratio, after 5 seconds
  
function bannerMake() {
		b.layer.css('background-color','yellow') //layer 1
		b.next(tl,0,'left',1,'spin right',2,-1).css('background','blue') //animate to layer 2
		tl.to(b.layer,3,{rotation:-720}) //do a spin
		tl.to(b.layer,3,{left:b.w},'+=2') //slide out
 }
              
            
!
999px
A Pen is worth a thousand docs.

Console