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

              
                <section class="demo card-demo">
  <div class="demo-content flexbox-columns">
    <div class="column">
      <div class="card">
        <div class="card-content">Module</div>
      </div>
      <div class="card">
        <div class="card-content">Module</div>
      </div>
      <div class="card">
        <div class="card-content">Module</div>
      </div>
    </div>

    <div class="column">
      <div id="movable-card" class="card large interactive">
        <div class="card-content">Click me!</div>
      </div>
      <div class="card">
        <div class="card-content">Module</div>
      </div>
    </div>
  </div>
</section>

<section class="demo twitch-demo">  
  <div class="demo-content twitch-style-minimize">    
    <video 
           id="twitch-minimize-video" 
           class="minimizable interactive" 
           autoplay="" 
           loop="" 
           muted="" 
           src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/train.mp4">
    Your browser doesn't seem to support videos :(
    </video>
    
    <div id="twitch-minimize-video-placeholder" class="placeholder"></div>

    <p class="placeholder">
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
    </p>

  </div>
</section>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  position: relative;
}

html {
  background: #fff;  
  font-family: "Open Sans", sans-serif;
  font-size: 20px;
  line-height: 1.4;
  color: #222;
  overflow-x: hidden;
}

body {
  height: 3000px;  
  background: #eee;
}

.demo {
  display: flex;
  align-items: stretch;
  margin-bottom: 50px;
}

.card-demo {
  height: 600px;
}

.twitch-demo {
  
}

.demo-content {
  position: relative;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  padding: 1em;
  flex-shrink: 1;
  flex-grow: 1;
  width: 50%;
  min-width: 256px;
  background: #eee;
}

.card {
  position: relative;
  flex-grow: 1;
  min-height: 64px;
  margin-bottom: 16px;
  padding: 16px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.card.large {
  flex-grow: 2;
  min-height: 145px;
}

.card:last-child {
  margin-bottom: 0;
}

.interactive {
  cursor: pointer;
  will-change: transform;
}

.column:last-child {
  margin-right: 0;
}

.column {
  display: flex;
  flex-grow: 1;
  flex-direction: column;
  margin-right: 8px;
}

.card-content {
  color: #bbb;
  font-size: 24px;
  user-select: none;
}

.interactive .card-content {
  color: #222;
}

.minimizable {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  transition: box-shadow 0.4s;
  width: 100%;
  height: auto;
  cursor: pointer; 
  z-index: 10;
}

.minimizable.minimized {
  width: 150px;
  position: fixed;
  bottom: 10px;
  left: 10px;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.minimizable.minimized {
  width: 150px;
  position: fixed;
  bottom: 10px;
  left: 10px;
}

#twitch-minimize-video-placeholder {
  display: none;  
  width: 100%;
  padding-bottom: 56.20%;
}

.minimized + #twitch-minimize-video-placeholder {
  display: block;
}

.placeholder {
  
}

p.placeholder {
  border: none;
  width: 100%;
  margin: 1em 0;
}

p.placeholder span {
  display: block;
  width: 80%;
  height: 1ex;
  background: #bbb;
  margin-bottom: 0.5em;
}

p.placeholder span:nth-child(2) {
  width: 60%;
}

p.placeholder span:nth-child(3) {
  width: 65%;
  margin-bottom: 1.5em;
}

p.placeholder span:nth-child(4) {
  width: 70%;
}

p.placeholder span:nth-child(5) {
  width: 65%;
}

p.placeholder span:nth-child(6) {
  width: 70%;
}

p.placeholder span:last-child {
  margin-bottom: 0;
}

p.placeholder:last-child {
  margin-bottom: 0;
}

.twitch-style-minimize {
  flex-direction: column;
}

              
            
!

JS

              
                console.clear();

function demo() {
    
  const video = document.querySelector("#twitch-minimize-video");
  const cards = document.querySelectorAll(".flexbox-columns .card");
  const movableCard = document.querySelector("#movable-card");
  const parents = [
    document.querySelector(".flexbox-columns"),
    document.querySelector(".flexbox-columns .column:nth-child(2)")
  ];
  
  movableCard.addEventListener("click", () => {
    
    Flipper.flip(cards, cardModifier, {
      ease: new CustomEase("", "M0,0 C0.4,2.2 0.5,0.7 1,1"),
      // onComplete: () => console.log("Card onComplete")
    });
  });
  
  video.addEventListener("click", () => {    
    
    Flipper
      .flip(video, videoModifier)
      // .then(() => console.log("Video promise"))
  });
  
  function cardModifier() {
    const parent = movableCard.parentNode === parents[0] ? parents[1] : parents[0];  
    parent.insertBefore(movableCard, parent.firstChild);
  }
  
  function videoModifier() {
    video.classList.toggle("minimized");
  }  
}



//
// FLIPPER
// ===========================================================================
namespace Flipper {
  
  const body = document.body;
  const html = document.documentElement;  
  const elementMap = new Map();  
  
  //
  // RECTANGLE
  // ===========================================================================
  class Rectangle {
        
    constructor(public x = 0, public y = 0, public width = 0, public height = 0) {

    }
    
    set(x = 0, y = 0, width = 0, height = 0) {
      this.x = x;
      this.y = y;
      this.width = width;
      this.height = height;
      return this;
    }
    
    get x2() {
      return this.x + this.width;
    }
    
    get y2() {
      return this.y + this.height;
    }
    
    get centerX() {
      return this.x + this.width / 2;
    }
    
    get centerY() {
      return this.y + this.height / 2;
    }
    
    clone() {
      return new Rectangle(this.x, this.y, this.width, this.height);
    }
    
    copy(rectangle) {
      this.x = rectangle.x;
      this.y = rectangle.y;
      this.width = rectangle.width;
      this.height = rectangle.height;
      return this;
    }
  }
  
  
  //
  // SNAP SHOT
  // ===========================================================================
  class SnapShot extends Rectangle {
        
    constructor(public flipElement) {
      super();
    }
    
    save() {
      const flipElement = this.flipElement;
      getPosition(flipElement, this);
      this.opacity = flipElement.computedStyle.opacity;
    }
  }
  
  
  //
  // FLIP ELEMENT
  // ===========================================================================
  export class FlipElement {
    
    constructor(public element) {
      
      TweenLite.set(element, { x: "+=0", overwrite: false });
      this.transform = element._gsTransform;      
      this.computedStyle = getComputedStyle(element);
      this.bounds = new Rectangle();
      
      this.snapShot1 = new SnapShot(this);
      this.snapShot2 = new SnapShot(this);
    }
    
    get isFixed() {
      return this.computedStyle.position === "fixed";
    }   
    
    destroy() {
      
    }
    
    setOptions(options) {
      this.options = options;
      return this;
    }
    
    first() {
      this.snapShot1.save();
      return this;
    }

    last() {
      this.snapShot2.save();
      return this;
    }

    invert(timeline, options) {
           
      const { 
        useExpoScale,
        fromCenter,
        duration, 
        ease, 
        minScale 
      } = options;
      
      const element = this.element;
      const children = element.children;
      const transform = this.transform;
      
      const first = this.snapShot1;
      const last = this.snapShot2;
            
      const x1 = fromCenter ? first.centerX : first.x;
      const y1 = fromCenter ? first.centerY : first.y;
      const x2 = fromCenter ? last.centerX : last.x;
      const y2 = fromCenter ? last.centerY : last.y;
      
      const w1 = first.width;
      const h1 = first.height;      
      const w2 = last.width;
      const h2 = last.height;
      
      let xEase = ease;
      let yEase = ease;      
      let tl;
            
      if (w1 !== w2 || h1 !== h2) {
        
        tl = tl || new TimelineLite();
        
        const scaleX = transform.scaleX * w1 / w2;
        const scaleY = transform.scaleY * h1 / h2;        

        TweenLite.set(element, { scaleX, scaleY });        
        
        xEase = useExpoScale ? ExpoScaleEase.config(scaleX, 1, ease) : ease;
        yEase = useExpoScale ? ExpoScaleEase.config(scaleY, 1, ease) : ease;

        if (scaleX !== 1) {

          tl.to(element, duration, {
            scaleX: 1,
            ease: xEase,
          }, 0);
        }

        if (scaleY !== 1) {

          tl.to(element, duration, {
            scaleY: 1,
            ease: yEase
          }, 0);
        }
        
        if (children) {
          
          const invScaleX = 1.0 / (scaleX || minScale);
          const invScaleY = 1.0 / (scaleY || minScale);
          
          TweenLite.set(children, {
            scaleX: invScaleX,
            scaleY: invScaleY
          });
          
          if (invScaleX !== 1) {

            tl.to(children, duration, {
              scaleX: 1,
              ease: ExpoScaleEase.config(invScaleX, 1, ease)
            }, 0);
          }

          if (invScaleY !== 1) {

            tl.to(children, duration, {
              scaleY: 1,
              ease: ExpoScaleEase.config(invScaleY, 1, ease)
            }, 0);
          }
        }       
      }
            
      if (x1 !== x2 || y1 !== y2) {
        
        tl = tl || new TimelineLite();
      
        TweenLite.set(element, {
          x: transform.x + x1 - x2,
          y: transform.y + y1 - y2
        });            
        
        tl.to(element, duration, { x: 0, ease: xEase }, 0);        
        tl.to(element, duration, { y: 0, ease: yEase }, 0);        
      }
      
      if (tl) {
        timeline.add(tl, 0);
      }
      
      return this;
    }
  }
  
  
  //
  // FLIP
  // ===========================================================================
  export function flip(elements, modifier, options = {}) {
    
    if (!elements.length) {
      elements = [elements];
    }
    
    options = Object.assign({
      duration: 0.4,
      ease: Power1.easeInOut,
      useScale: true,
      minScale: 0.01,
      fromCenter: true,
      useExpoScale: true,
    }, options);   
    
    let onComplete;    
    const promise = new Promise(resolve => {
      onComplete = () => {
        if (options.onComplete) {
          options.onComplete();
        }
        resolve();
      };
    });
    
    const timeline = new TimelineMax({
      onComplete: () => {
        onComplete();
      }
    });
    
    const flipElements = [];
    
    for (let i = 0; i < elements.length; i++) {
      const element = elements[i];
      let flipElement;
      
      if (elementMap.has(element)) {
        flipElement = elementMap.get(element);
      } else {
        flipElement = new FlipElement(element);
        elementMap.set(element, flipElement);
      }
      flipElements.push(flipElement);
    }
      
    for (let flipElement of flipElements) {
      flipElement.first();
    }
    
    modifier();
    
    for (let flipElement of flipElements) {
      flipElement.last();
    }
    
    for (let flipElement of flipElements) {
      flipElement.invert(timeline, options);
    }
    
    body.offsetTop; // force reflow
            
    return promise;    
  }
  
  
  //
  // GET POSITION
  // ===========================================================================
  function getPosition(flipElement, rect = new Rectangle()) {
    
    let element = flipElement.element;
    let x = element.offsetLeft;
    let y = element.offsetTop;
    let width = element.offsetWidth;
    let height = element.offsetHeight;
    
    while ((element = element.offsetParent) && element !== body && element !== html) {
      x += element.offsetLeft;
      y += element.offsetTop;
    }
    
    if (flipElement.isFixed) {
      x += (window.pageXOffset || html.scrollLeft) - (html.clientLeft || 0);
      y += (window.pageYOffset || html.scrollTop) - (html.clientTop || 0);
    }
    
    return rect.set(x, y, width, height);    
  }
}



demo();
              
            
!
999px

Console