cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <div id="animaton">
	<div id="stage">
    
		<div class="location" id="street">
			<span>Street Element</span>
		</div>

		<div class="location" id="store">
			<span>Store Element</span>
		</div>

		<div class="location" id="bank">
			<span>Bank Element</span>
		</div>
    
	</div>

	<div id="info"></div>
  
</div>


[[[https://codepen.io/davestewart/pen/itCkj]]]


            
          
!
            
              /* layout */
body{
  width:800px;
  font:12px normal "Arial", sans-serif;
}

#stage {
  position:relative;
  height:200px;
  background-color:black;
  border:4px solid #000;
}
    
#info{
  padding:4px 6px;
  background:#000;
  color:#FFF;
  }

/* elements */
.location {
  width:100%;
  height:100%;
  position:absolute;
  background-position:center center;
  font-size:20px;
  z-index:0;
    
  span{
    position:absolute;
    display:inline-block;
    left:10px;
    top:10px;
    padding:5px 9px;
    background:#000;
    color:#FFF;
  }
}

$url:'https://www.davestewart.co.uk/temp/gsap/locations/';
    
#street { 
  background-image:url($url + 'street.png');
}

#store { 
  background-image:url($url + 'store.png');
  span{
    top:50px;
    }
}

#bank { 
  background-image:url($url + 'bank.png');
  span{
    top:90px;
    }
}
            
          
!
            
              // event handlers
	function onStart()
	{
    $('#info').text('Starting: ' + this.vars.name);
	}

// functions
	function timeline(id)
	{
   	// variables
   		++zIndex;
			var slide = id;
			var title = $(id).find('span');
   		var name = 'scene ' + zIndex + ' (' +id.replace('#', '')+ ')';
			var props = {name:name, onStart:onStart};
			var tl = new TimelineLite(props);
    
   	// set main timeline label
   		tlMain.addLabel(name);
    
   	// animate
   		tl
      
      		//pop slide to top of stack and set transparent
      		.set(slide, {zIndex:zIndex, autoAlpha:0, immediateRender:false})
      
      		// reset title
      		.set(title, {left:10, immediateRender:false})
      
      		// fade in
      		.to(slide, 0.5, {autoAlpha:1})
    
   			// animate title
				.to(title, 1, {left:200});
      
      // return
			return tl;
	}

// variables
	var zIndex = 0;
	var tlMain = new TimelineMax({name:'main'});

// preemptively set all timelines to 0 z-index and 0 alpha
	TweenMax.set($('.slide'), {zIndex:0, autoAlpha:0})

// animation, round 1
   tlMain.add(timeline('#street'));
	tlMain.add(timeline('#store'));
	tlMain.add(timeline('#bank'));

// animation, round 2
   tlMain.add(timeline('#street'));
	tlMain.add(timeline('#store'));
	tlMain.add(timeline('#bank'));

// controller
	Controller.init(tlMain);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console