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

              
                <div id="main-stage">
  <div class="conrner-nav">

    <div id="print" class="media-type">
      <div id="print-content" class="card-content">
        <a href="#">
          <div id="printLinkSpace"><span id="print-title" class="title-print"><h2>print</h2></span></div>
        </a>
        <img src="https://dummyimage.com/700x521/ffffff/ebebeb.gif" alt="Print Portfolio Samples">
      </div>
    </div>

    <div id="broadcast" class="media-type">
      <div id="broadcast-content" class="card-content">
        <a href="#">
          <div id="broadcastLinkSpace">
            <span id="broadcast-title"><h2>video</h2></span>
          </div>
        </a>
        <img src="https://dummyimage.com/700x488/ffffff/ebebeb.gif" alt="Broadcast Portfolio Samples">
      </div>
    </div>

    <div id="outdoor" class="media-type">
      <div id="outdoor-content" class="card-content">
        <a href="#">
          <div id="outdoorLinkSpace">
            <span id="outdoor-title"><h2>outdoor</h2></span>
          </div>
        </a>
        <img src="https://dummyimage.com/700x705/ffffff/ebebeb.gif" alt="Outdoor Portfolio Samples">
      </div>
    </div>

    <div id="online" class="media-type">
      <div id="online-content" class="card-content">
        <a href="#">
          <div id="onlineLinkSpace">
            <span id="online-title"><h2>online</h2></span>
          </div>
        </a>
        <img src="https://dummyimage.com/700x564/ffffff/ebebeb.gif" alt="Online Portfolio Samples">
      </div>
    </div>

  </div>
</div>
              
            
!

CSS

              
                /* *********************** */
/* ***** Main Styles ***** */
/* *********************** */


/* warm gray */
body {
  overflow: hidden;
  margin: 0;
  padding: 0;
  background-color: #afafaf; 
}

h2 {
  font-size: 2.5rem;
}

div {
  border: 1px solid red; 
}

span {
  border: 1px solid green; 
}

/* ********************************* */
/* ******** Section - Styles ******* */
/* ********************************* */
#main-stage {
  width: 100vw;
  height: 100vh; 
}

.conrner-nav {
  width: 100vw;
  height: 100vh; 
}

.media-type {
    position: fixed;
    display: inline-block; 
}

.media-type img {
  position: relative;
  display: inline-block;
  height: 100%; }

#print {
  position: absolute;
  visibility: hidden;
  background-color: #ffff;
  width: 700px;
  height: 521px;
  top: 50%;
  left: 50%;
  z-index: 2;
}

#printLinkSpace {
  position: absolute;
  overflow: hidden;
  width: 700px;
  height: 521px;
  bottom: 0;
  right: 0;
  z-index: 2;

}

#broadcast {
  position: absolute;
  visibility: hidden;
  background-color: #ffff;
  width: 700px;
  height: 488px;
  top: 50%;
  left: 50%;  
  z-index: 2;
}

#broadcastLinkSpace {
  position: absolute;
  overflow: hidden;
  width: 700px;
  height: 488px;
  bottom: 0;
  left: 0;
  z-index: 2;

}

#outdoor {
  position: absolute;
  visibility: hidden;
  background-color: #ffff;
  width: 700px;
  height: 705px;
  top: 50%;
  left: 50%;
  z-index: 2;
}

#outdoorLinkSpace {
  position: absolute;
  overflow: hidden;
  width: 700px;
  height: 705px;
  top: 0;
  right: 0;
  z-index: 2;
}

#online {
  position: absolute;
  visibility: hidden;
  background-color: #ffff;
  width: 700px;
  height: 564px;
  top: 50%;
  left: 50%;
  z-index: 2;
}

#onlineLinkSpace {
  position: absolute;
  overflow: hidden;
  width: 700px;
  height: 564px;
  top: 0;
  left: 0;
  z-index: 2;
}

/* ********************************* */
#print-title {
  position: absolute;
  bottom: 0;
  right: 0;
  margin: 2%;
  z-index: 4; 
}


/* ********************************* */
#broadcast-title {
  position: absolute;
  bottom: 0;
  left: 0;
  margin: 2%;
  z-index: 4; 
}


/* ********************************* */
#outdoor-title {
  position: absolute;
  top: 0;
  right: 0;
  margin: 2%;
  z-index: 4; 
}


/* ********************************* */
#online-title {
  position: absolute;
  top: 0;
  left: 0;
  margin: 2%;
  z-index: 4; 
}


.card-content {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  
  overflow: hidden;
  
  // border: 5px solid blue;
}
              
            
!

JS

              
                console.clear();
var log = console.log.bind(console);


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

var cx = vw / 2;
var cy = vh / 2;

var cards = null;
var scale = 0; 
var space = Math.min(vw * 0.35, vh * 0.35);

var space = 200;

var duration = 2;
var selected = null;
var hasChanges = true;
var mediaQueries = {};

var cardOptions = [
  { enterAngle:  15, leaveAngle: -60, baseW: 700, baseH: 521, xSign: -1, ySign: -1, name: "print" },
  { enterAngle: -15, leaveAngle:  60, baseW: 700, baseH: 488, xSign:  1, ySign: -1, name: "broadcast" },
  { enterAngle: -15, leaveAngle:  60, baseW: 700, baseH: 705, xSign: -1, ySign:  1, name: "outdoor" },
  { enterAngle:  15, leaveAngle: -60, baseW: 700, baseH: 564, xSign:  1, ySign:  1, name: "online" }
];

var mediaOptions = [  
  { name: "small",  scale: 0.9, query: "(max-width: 400px)" },
  { name: "medium", scale: 0.6, query: "(min-width: 400px)  and (max-width: 1000px)" },
  { name: "large",  scale: 0.5, query: "(min-width: 1000px)" }
];

// Base animation object to extend - DRY principle
var baseAnimation = {      
  x: 0,
  y: 0, 
  reversed: true,
  progress: 0,
  bezier: {
    type: "quadratic",
    values: []
  }
};

//
// INIT
// ===================================================================
function init() {
  
  // Add media query listeners
  $.each(mediaOptions, addMediaQuery);
    
  // Map card objects
  // https://api.jquery.com/map/
  cards = $(".media-type").map(createCard);
  
  update();
  
  cards.each(function(i, card) {        
    card.show();
  }); 
  
  // Calls update on every animation frame to check for changes
  // https://greensock.com/docs/#/HTML5/GSAP/TweenLite/ticker/
  TweenLite.ticker.addEventListener("tick", update);
  
  $(window).resize(queueUpdate);
  
  // You can inspect the card objects in the console
  log("CARDS", cards);
}


//
// CREATE CARD
// ===================================================================
function createCard(i, element) {
  
  var config = cardOptions[i];
    
  var id = "#" + config.name;
  
  var $element = $(element);
  var $content = $(id + "-content");
  
  // Extend base animation object for enter and leave animation objects
  // https://api.jquery.com/jquery.extend/
  var enter = $.extend(true, {}, baseAnimation, {
    tl: new TimelineMax().reverse(),
    clear: clearAnimation
  });
  
  var leave = $.extend(true, {}, baseAnimation, {
    tl: new TimelineMax().reverse(),
    clear: clearAnimation
  });
  
  // Card object - properties from the config object will be added to it
  var card = $.extend({}, config, {
    
    // Properties
    element: $element,
    content: $content,
    link:  $(id + "LinkSpace"),
    title: $(id + "-title"),    
    enter: enter,
    leave: leave,    
    
    // Methods
    init: initCard,
    show: showCard    
  });
  
  TweenLite.set([$element, $content], { force3D: true });
  
  TweenLite.set($element, {
    rotation: card.enterAngle,
    xPercent: -50,
    yPercent: -50
  });
  
  $element.click(function(event) {
    layout(card);
  });
   
  function initCard() {
    
    var r1 = (vw - space) / this.baseW;
    var r2 = (vh - space) / this.baseH;

    var ratio = Math.min(r1, r2);

    enter.clear();
    leave.clear();

    TweenLite.set(element, {
      width:  card.baseW * ratio,
      height: card.baseH * ratio,
      scale: scale,
      x: enter.x,
      y: enter.y
    });

    // Updates bezier values
    setBezier(card);

    // Build timelines
    enter.tl
      .to(card.element, duration, { bezier: enter.bezier, scale: 1, rotation: 0 }, 0)
      .to(card.link, 0.25, { autoAlpha: 0 }, 0)
      .progress(enter.progress)
      .reversed(enter.reversed);

    leave.tl
      .to(card.content, duration, { bezier: leave.bezier, rotation: card.leaveAngle })
      .progress(leave.progress)
      .reversed(leave.reversed);
  }
   
  function showCard() {
    TweenLite.set(element, { autoAlpha: 1 });
  }
  
  function clearAnimation() {
        
    // 'this' refers to the object calling this function
    // i.e. the enter or leave animation object 
    
    this.x = cx * card.xSign;
    this.y = cy * card.ySign;
        
    this.progress = this.tl.progress() || 0;
    this.reversed = this.tl.reversed() || false;
    this.tl.seek(0).clear();
  }
   
  // Return object to map to cards
  return card;  
}

//
// SET BEZIER
// ===================================================================
function setBezier(card) {
  
  var enter = card.enter;
  var leave = card.leave;
   
  var x1 = enter.x;
  var y1 = enter.y;
  
  var x2 = leave.x;
  var y2 = leave.y;
  
  // Switch statement - similar to else if statements
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch
  switch (card.name) {
      
    case "print":      
      enter.bezier.values = [
        { x: x1, y: y1 },
        { x: x1, y: 0  },
        { x: 0,  y: 0  }
      ];
      
      leave.bezier.values = [
        { x: 0,  y: 0  },
        { x: 0,  y: y2 },
        { x: x2, y: y2 }
      ];      
      break;
      
    case "broadcast":            
      enter.bezier.values = [
        { x: x1, y: y1 },
        { x: x1,  y: 0 },
        { x: 0,  y: 0  }
      ];
      
      leave.bezier.values = [
        { x: 0,  y: 0  },
        { x: x2, y: 0  },
        { x: x2, y: y2 }
      ];      
      break;
      
    case "outdoor":      
      enter.bezier.values = [
        { x: x1, y: y1 },
        { x: x1, y: 0  },
        { x: 0,  y: 0  }
      ];
      
      leave.bezier.values = [
        { x: 0,  y: 0 },
        { x: x2,  y: 0 },
        { x: x2, y: y2 }
      ];      
      break;
      
    case "online":      
      enter.bezier.values = [
        { x: x1, y: y1 },
        { x: x1,  y: 0 },
        { x: 0,  y: 0  }
      ];
      
      leave.bezier.values = [
        { x: 0,  y: 0  },
        { x: x2, y: 0  },
        { x: x2, y: y2 }
      ];      
      break;
  }  
}

//
// UPDATE
// ===================================================================
function queueUpdate() {  
  hasChanges = true;
}

function update() {
  
  // Exit if there are no changes
  if (!hasChanges) { return; }
  
  vw = $(window).width();
  vh = $(window).height();

  cx = vw / 2;
  cy = vh / 2;
    
  space = Math.min(vw * 0.35, vh * 0.35);
  
  cards.each(function(i, card) {        
    card.init();
  });
  
  hasChanges = false;
}

//
// LAYOUT
// ===================================================================
function layout(corner) {
  
  selected = corner;
  
  var reversed = !corner.enter.tl.reversed();
  
  cards.each(function(i, card) {
    
    if (reversed) {
      
      card.enter.tl.reversed(true);
      card.leave.tl.reversed(true);
            
    } else {
      
      if (card === selected) {        
        
        card.enter.tl.reversed(false);
        card.leave.tl.reversed(true);        
        
      } else {
        
        card.enter.tl.reversed(true);
        card.leave.tl.reversed(false);        
      }
    }    
  });
}

//
// MEDIA QUERIES
// ===================================================================
function addMediaQuery(i, media) {
    
  var mql = matchMedia(media.query);  
  var listener = $.proxy(onMediaChange, this, media.name);
  
  mql.addListener(listener);
  
  mediaQueries[media.name] = { listener: listener, mql: mql, scale: media.scale };
  
  // Initial run of query
  onMediaChange(media.name, mql);
}

function onMediaChange(name, mql) {
      
  // jQuery each method for object
  // https://api.jquery.com/jquery.each/
  $.each(mediaQueries, function(key, media) {
    
    if (key === name && mql.matches) {      
      scale = media.scale;      
      hasChanges = true;
    }   
  });
}


// Inialize App
init();









              
            
!
999px

Console