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

              
                <main>
  <section class="header">

    <div class="title">My App Name</div>
  </section>

  <section class="content">

    <div class="card1 card-container">

      <div class="ripple-container">
        <div class="ripple"></div>
      </div>

      <div class="card">

        <div class="card-header">
          <div class="title">Card 1</div>
          <div class="items-inline">
            <div class="icon-button expand-button">
              <i class="material-icons icon">fullscreen</i>
            </div>
            <div class="icon-button close-button">
              <i class="material-icons icon">close</i>
            </div>
          </div>
        </div>

        <div class="card-text">
          Lorem ipsum dolor sit amet, id pri eros probo aeque, eos summo vitae lucilius ad, ea vim tale stet delectus. Viris feugiat inermis ius eu, sed an esse commune percipitur. Meis efficiendi eum in, mea at copiosae verterem. Vim no omittam mentitum principes.
          Mei in magna recteque ocurreret, abhorreant definitionem an qui.
        </div>

        <div class="card-footer">
          <div class="icon-button back-button">
            <i class="material-icons icon">arrow_back</i>
          </div>
          <div class="btn" style="text-align: center">Animate to Box Below</div>
          <div class="icon-button forward-button">
            <i class="material-icons icon">arrow_forward</i>
          </div>
        </div>
      </div>
    </div>

    <div class="card2 card-container">

      <div class="ripple-container">
        <div class="ripple"></div>
      </div>

      <div class="card">

        <div class="card-header">
          <div class="title">Card 2</div>
          <div class="items-inline">
            <div class="icon-button expand-button">
              <i class="material-icons icon">fullscreen</i>
            </div>
            <div class="icon-button close-button">
              <i class="material-icons icon">close</i>
            </div>
          </div>
        </div>

        <div class="card-text">
          Some text
        </div>

        <div class="card-footer">
          <div class="icon-button back-button">
            <i class="material-icons icon">arrow_back</i>
          </div>
          <div class="btn" style="text-align: center">Animate to Box Above</div>
          <div class="icon-button forward-button">
            <i class="material-icons icon">arrow_forward</i>
          </div>
        </div>
      </div>
    </div>

    <div class="circle-container">
      <div class="circle">
        <i class="material-icons icon">add</i>
      </div>
    </div>

  </section>

  <section class="footer">
    <div class="title">Material Design Motion with GSAP</div>
  </section>
</main>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100%;
  background: #eee;
}

main {
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  opacity: 0;
}

.header {
  width: 100%;
  height: 56px;
  background: #1F2B49;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.2), 0 1px 1px rgba(0,0,0,.14), 0 2px 1px -1px rgba(0,0,0,.12);
}

.header .title {
  padding: 0 16px 0 16px;
  color: rgba(255, 255, 255, 0.87);
  padding: 0 16px 0 16px;
}

.content {
  padding: 16px;
  position: relative;
  flex: 1;
}

.footer {
  height: 56px;
  width: 100%;
  background: #171E33;
  display: flex;
  align-items: center;
}

.footer .title {
  padding: 0 16px 0 16px;
  color: rgba(255, 255, 255, 0.7);
}

.card-container {
  min-height: 150px;
  max-height: 40vh;
  overflow: hidden;
  position: relative;
  border-radius: 2px;
  margin-bottom: 16px;
}

.card1 {
  height: 300px;
  border: dashed 1px red;
}

.card2 {
  height: 200px;
  border: dashed 1px blue;
}

.card {
  height: 100%;
  color: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 2px;
  visibility: hidden;
  opacity: 0;
}

.card-header {
  height: 56px;
  width: 100%;
  display: flex;
  align-items: center;
}

.items-inline {
  display: flex;
  align-items: center;
}

.card-footer {
  height: 72px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
}

.card-header .title {
  flex: 1;
  padding: 0 16px 0 16px;
}

.card-header .close-button {
  padding: 16px;
  cursor: pointer;
}

.card-text {
  width: 100%;
  flex: 1;
  padding: 16px;
  color: rgba(255,255,255, 0.54);
}

.icon-button {
  cursor: pointer;
}

.btn {
  background-color: #6CBC35;
  height: 48px;
  border-radius: 2px;
  padding: 16px 32px 16px 32px;
  diplay: flex;
  align-items: center;
  cursor: pointer;
}

.btn-raised {
    box-shadow: 0 1px 5px rgba(0, 0, 0, .2), 0 2px 2px rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .12);
}

.circle-container,
.ripple-container {
  position: absolute;
  width: 72px;
  height: 72px;
}

.circle-container {
  top: calc(100% - 72px);
  // left: 0;
  // margin: -16px 0 0 16px;
  left: calc(100% - 72px);
  margin: -16px;
}

.ripple-container {
  border-radius: 2px;
  top: 0;
  left: 0;
}

.circle,
.ripple {
  position: absolute;
  width: 72px;
  height: 72px;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  cursor: pointer;
  background: #1167A0;
}

.ripple {
  visibility: hidden;
}

.circle {
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 5px rgba(0,0,0,.2), 0 2px 2px rgba(0,0,0,.14), 0 3px 1px -2px rgba(0,0,0,.12);
}

.circle i {
  color: #fff;
}
              
            
!

JS

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

var kappa = 0.551915024494;

var cardNum = 1; //Change number to switch cards (1 or 2)

var cardContainer = document.querySelector(".card" + cardNum);
var circleContainer = document.querySelector(".circle-container");
var rippleContainer = cardContainer.querySelector(".ripple-container");
var circle = document.querySelector(".circle");
var circleIcon = circle.querySelector("i");
var ripple = cardContainer.querySelector(".ripple");
var card = cardContainer.querySelector(".card");
var closeButton = cardContainer.querySelector(".close-button");
var root = document.documentElement;
var body = document.body;

var cardStyle = {
  background: '#1167A0',
  boxShadow: '0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2)'
};

var p0 = { x: 0, y: 0 };
var p1 = { x: 0, y: 0 };
var p2 = { x: 0, y: 0 };
var p3 = { x: 0, y: 0 };

var bezier = { values: [p0, p1, p2, p3], type: "cubic" };
var cursor = { x: 0, y: 0 };

var circleBounds = getBounds(circleContainer);
var rippleBounds = getBounds(cardContainer);

var radius = circleBounds.w2;
var padding = -radius;
var duration = 0.5;
var requestId = null;

var standardCurve = new CustomEase("standardCurve", "0.4, 0.0, 0.2, 1");
TweenLite.defaultEase = standardCurve;

TweenLite.set([circle, ripple], { xPercent: -50, yPercent: -50 });

var tl = new TimelineMax({ reversed: true });

circle.addEventListener("click", toggleAnimation);
closeButton.addEventListener("click", toggleAnimation);
window.addEventListener("resize", requestUpdate);

TweenLite.set("main", { autoAlpha: 1 });

function toggleAnimation() {
  
  update();
  
  tl.reversed(!tl.reversed());
}

function update() {
  
  console.log('update');
  
  var progress = tl.progress() || 0;
  var reversed = tl.reversed() || false;
  
  tl.progress(0).clear();
  
  circleBounds = getBounds(circleContainer);
  rippleBounds = getBounds(cardContainer);
  
  updateBezier();
  
  var delay = getDelay();
  
  var dt = duration - delay;
  var dx = rippleBounds.w2;
  var dy = rippleBounds.h2;
  var tx = dx - radius - p3.x;
  var ty = dy - radius - p3.y;
  
  var size = Math.sqrt(dx * dx + dy * dy) * 2;
  
  TweenLite.set(rippleContainer, { x: tx, y: ty });
  
  var circleClone;
  
  var clones = circleContainer.querySelectorAll('.circle.clone');
  
  if(clones.length === 0) {
    
    circleClone = circle.cloneNode(true);
    circleClone.classList.add('clone');
    circleClone.style.left = 0;
    circleClone.style.top = 0;
    
    circleContainer.insertBefore(circleClone, circleContainer.firstChild);
  }
  else
    circleClone = clones[0];

  tl.set(circle, { autoAlpha: 1 })
    .set([card, circle], { autoAlpha: 0 })
    .set(circleClone, { autoAlpha: 0 })
    .set([ripple, circleClone], { autoAlpha: 1 })
    .to([circleClone, ripple], duration, { bezier }, 0)
    .to(circleIcon, duration, { autoAlpha: 0 }, 0)
    .to(ripple, dt, { width: size, height: size, onComplete: () => {
      tl.set(cardContainer, { borderWidth: 0, background: cardStyle.background, boxShadow: cardStyle.boxShadow })
        .set([ripple, circleClone], { autoAlpha: 0, scale: 0 })
        .set(card, { autoAlpha: 1 })
    } }, delay)
    .to(circleClone, dt, { autoAlpha: 0, scale: 0 }, delay)
    .progress(progress)
    .reversed(reversed);
  
  requestId = null;
}

function updateBezier() {
  
  p3.x = rippleBounds.cx - circleBounds.cx;
  p3.y = rippleBounds.cy - circleBounds.cy;
  
  var dx = p3.x - p0.x;
  var dy = p3.y - p0.y;

  if (p3.y > p0.y) {

    p1.x = p0.x;
    p1.y = p0.y + (dy * kappa);  
    p2.x = p3.x - (dx * kappa);
    p2.y = p3.y;

  } else {

    p1.x = p0.x + (dx * kappa);
    p1.y = p0.y;  
    p2.x = p3.x;
    p2.y = p3.y - (dy * kappa);
  }
}

function getDelay() {
  
  cursor.x = p0.x;
  cursor.y = p0.y;
   
  var k = 0.0001;
  
  var cx = circleBounds.cx;
  var cy = circleBounds.cy;
  
  var rx = rippleBounds.x + padding;
  var ry = rippleBounds.x + padding;
  var rw = rippleBounds.w - padding * 2;
  var rh = rippleBounds.h - padding * 2;  
  
  var delay = 0;
  
  var tween = TweenLite.to(cursor, duration, { bezier, paused: true });
  
  for (var i = 0; i <= 1; i += k) {

    tween.progress(i);
    
    var x = cx + cursor.x;
    var y = cy + cursor.y;
    
    if (pointInRect(x, y, rx, ry, rw, rh)) {
      delay = tween.time();
      break;
    }
  }
  
  return delay;
}

function getBounds(element) {
  
  var rect = element.getBoundingClientRect();
    
  var scrollTop  = window.pageYOffset || root.scrollTop  || body.scrollTop  || 0;
  var scrollLeft = window.pageXOffset || root.scrollLeft || body.scrollLeft || 0;

  var clientTop  = root.clientTop  || body.clientTop  || 0;
  var clientLeft = root.clientLeft || body.clientLeft || 0;
    
  var x = Math.round(rect.left + scrollLeft - clientLeft);
  var y = Math.round(rect.top  + scrollTop  - clientTop);  
  
  var w = rect.width;
  var h = rect.height;
  var w2 = w / 2;
  var h2 = h / 2;
  var cx = x + w2;
  var cy = y + h2;  
  
  return { x, y, w, h, w2, h2, cx, cy };
}

function requestUpdate() {
  if (!requestId) {
    requestId = requestAnimationFrame(update);
  }
}

function pointInRect(px, py, rx, ry, rw, rh) {
  return px >= rx && py >= ry && px <= rx + rw && py <= ry + rh;
}

              
            
!
999px

Console