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

              
                <nav>
 <div id="print" class="media-type">
  <h2>Print</h2>
 </div>
 <div id="broadcast" class="media-type">
  <h2>Broadcast</h2>
 </div>
 <div id="outdoor" class="media-type">
  <h2>Outdoor</h2>
 </div>
 <div id="online" class="media-type">
  <h2>Online</h2>
 </div>
</nav>
              
            
!

CSS

              
                body {
  overflow: hidden;
  margin: 0;
  padding: 0;
  background-color: #afafaf; 
}

h2 {
  font-size: 1rem;
}


nav > div {
 position: fixed;
 display: block;
 cursor: pointer;
 
 background: #fff;
 width: 275;
 height: 229px;
}



nav > div > h2 {
 position: absolute;
}


nav > #print {
 left: 0;
 top: 0;
}

nav > #print > h2 {
 right: 4%;
 bottom: 0;
}

nav > #broadcast {
 right: 0;
 top: 0;
}

nav > #broadcast > h2 {
 left: 4%;
 bottom: 0;
}

nav > #outdoor {
 left: 0;
 bottom: 0;
}

nav > #outdoor > h2 {
 right: 4%;
 top: 0;
}

nav > #online {
 right: 0;
 bottom: 0;
}

nav > #online > h2 {
 left: 4%;
 top: 0;
}
              
            
!

JS

              
                var vw = $(window).width(),
    vh = $(window).height();

var print = {id:"#print", 
             start:{x:-50, y:-50, rot:15},
             center:{x:1, y:1},
             end:{x:-200, y:-200}
            },
    broadcast = {id:"#broadcast",
                 start:{x:50, y:-50, rot:-15},
                 center:{x:-1, y:1},
                 end:{x:200, y:-200}
                },
    outdoor = {id:"#outdoor",
               start:{x:-50, y:50, rot:-15},
               center:{x:1, y:-1},
               end:{x:-200, y:200}
              },
    online = {id:"#online",
              start:{x:50, y:50, rot:15},
              center:{x:-1, y:-1},
              end:{x:200, y:200}
             },
    buttons = [print, broadcast, outdoor, online],
    sizes = [
     {width:120, height:100},
     {width:200, height:166},
     {width:225, height:187},
     {width:275, height:229}
    ],
    current = null,
    tween = null;


// Initial positioning of the buttons
buttons.forEach(initialSet);

function initialSet(element, index, array) {
  TweenMax.set(element.id, {
   xPercent:element.start.x,
   yPercent:element.start.y,
   rotation:element.start.rot
  });
}




// Click events
$(print.id).click(onClick);
$(broadcast.id).click(onClick);
$(outdoor.id).click(onClick);
$(online.id).click(onClick);


function onClick(e) {
 var trg = e.currentTarget;
    
 if(!tween) {
  
  current = checkTween(trg);
    
  // Move everyone out except the current one
  var remainder = buttons.filter(checkArray);
  remainder.forEach(moveOut);
    
 
  tween = createTween(current);
  
 } else {
  
  // Move everyone back except the current one - Do a check on the array for that
  var remainder = buttons.filter(checkArray);
  remainder.forEach(moveBack);
  
  // Rewind the main tween
  tween.reverse();
  
 }
 
}

function checkTween(trg) {
 switch(trg.id) {
  case "print": return print;
  case "broadcast": return broadcast;
  case "outdoor": return outdoor;
  case "online": return online;
 }
}



function checkArray(value) {
 return value != current; 
}



function moveOut(element) {
 TweenMax.to(element.id, 0.7, {
  x:element.end.x,
  y:element.end.y,
  ease:Power2.easeInOut
 });
}

function moveBack(element) {
 TweenMax.to(element.id, 0.7, {
  x:0,
  y:0,
  ease:Power2.easeInOut
 });
}



function createTween(element, progress, reversed) {
  
 return TweenMax.fromTo(element.id, 1, {
  width:sizes[getIndex()].width,
  height:sizes[getIndex()].height
 },
 {
   bezier:[
    {x:0, y:0},
    {x:(element.center.x*vw)/4, y:(element.center.y*vh)/2.5},
    {x:(element.center.x*vw)/2, y:(element.center.y*vh)/2}
   ],
   rotation:0,
   width:"80vw",
   height:"80vh",
   ease:Power2.easeInOut,
   onReverseComplete: function() {
    // Flush the tween
    tween = null;
   }
  })
  .progress(progress || 0)
  .reversed(reversed || false);
}



function getIndex() {
 if(vh <= 200 ) {
  return 0;
 } else if (vh > 200 && vh <= 400) {
  return 1;
 } else if ( vh > 400 && vh <= 600) {
  return 2;
 } else {
  return 3;
 }
}




// Window events
$(window).resize(resize);

// Call resize once to make sure the buttons are of correct size
resize();


function resize() {
 
 
 // Update the center of the screen
 vw = $(window).width();
 vh = $(window).height();
 
  
  TweenMax.to(".media-type", 0.3, {width:sizes[getIndex()].width, height:sizes[getIndex()].height});
 


 
 if(tween) {  
  // Grab tween's progress and record it
  var progress = tween.progress(),
      reversed = tween.reversed();

  // Recreate the tween
  tween.pause(0);  
  tween = createTween(current, progress, reversed);
 }
}
              
            
!
999px

Console