<div class="container">
    
  <div class="block">Click anywhere and start dragging.</div>
  
  <div class="block">Bacon ipsum dolor amet hamburger salami fatback, beef ribs meatball picanha cow pancetta swine kielbasa spare ribs. Shoulder doner pork belly meatloaf chicken tail, bacon pork loin shank. Pancetta prosciutto pork rump biltong.</div>

  <div class="block">Tenderloin ball tip pork sausage ribeye tongue ham kielbasa shoulder bresaola leberkas tri-tip spare ribs pork chop. Chicken ground round sirloin, shank venison pork loin drumstick boudin rump. Fatback doner salami pig boudin biltong chicken ground round shankle hamburger landjaeger kevin. Meatball beef ribs meatloaf turducken corned beef beef bresaola picanha prosciutto. Short ribs shank bacon, ham brisket hamburger turkey biltong boudin pork chop swine prosciutto corned beef t-bone.</div>

  <div class="block">Fatback picanha pork flank landjaeger venison. Hamburger flank pork belly, pork chop swine t-bone beef ribs picanha chuck shankle beef cupim tenderloin pork loin. Biltong chuck spare ribs ham hock beef ribs sirloin frankfurter pastrami doner pork leberkas meatball ham shank. Shoulder cow sausage turkey chuck turducken pastrami picanha meatball t-bone jerky kevin.</div>  

  <div class="block">Landjaeger shoulder hamburger pancetta, ham hock ham t-bone doner shank frankfurter. Doner ham hock pork tail jowl sausage. Fatback andouille shank bacon sirloin salami pancetta meatball. Ham hock turkey pork loin ball tip corned beef, capicola filet mignon alcatra cow turducken kevin venison chicken.</div> 
</div>


html, body {
  height: 100%;
}

body {  
  background: black;  
  overflow: hidden;
  color: white;  
  cursor: ew-resize;
}

* {
  padding:0;
  margin:0;
}

.container {
  position: relative;
  float: left;
  background: #333;  
  min-height: 100%;  
  visibility: hidden;
}	

.block {
  margin: 10px 15px;
}
View Compiled

// Based on the work of Kevin Doughty
// https://github.com/kevindoughty/Hypermatic/tree/gh-pages
// https://github.com/KevinDoughty/Hypermatic
// http://kxdx.org
// https://twitter.com/KvnDy

// Custom Easing by Matt Gallagher, used with permission!
// http://www.cocoawithlove.com/2008/09/parametric-acceleration-curves-in-core.html 
// https://twitter.com/cocoawithlove

//
// DEMO
// ===========================================================================
function demo() {

  var container = new Container($(".container"));  

  var blocks = $$(".block");
  
  for (var i = 0; i < blocks.length; i++) {
    
    var split = new SplitText(blocks[i], { type: "words" });
    
    split.words.forEach(word => container.addChild(new Box(word)));
  } 
  
  var render = container.render.bind(container);
  var resize = container.resize.bind(container);
  var update = container.update.bind(container);
  
  Draggable.create(createElement("div"), {
    trigger: document,
    onPress: resize,
    onDrag:  resize
  }); 

  window.addEventListener("resize", update);
  
  TweenLite.ticker.addEventListener("tick", render);
  
  TweenLite.set(container.node, { autoAlpha: 1 });
}

//
// CUSTOM EASE
// ===========================================================================
class CustomEase extends Ease {  

  constructor(omega = 10, zeta = 0.75) {
    super();
    this.omega = omega;
    this.zeta  = zeta;
  }  
  
  getRatio(progress) {
    
    var omega = this.omega;
    var zeta  = this.zeta;
    var beta  = Math.sqrt(1.0 - zeta * zeta);
    
    progress = 1 - Math.cos(progress * Math.PI / 2);   
    progress = 1 / beta * 
      Math.exp(-zeta * omega * progress) * 
      Math.sin( beta * omega * progress + Math.atan(beta / zeta));
    
    return 1 - progress;
  }  
}

//                           
// CONTAINER
// ===========================================================================
class Container {

  constructor(node) {
    
    this.node  = node;
    this.ratio = 0.8553971486761711;
    this.width = body.offsetWidth * this.ratio;
    
    this.children = new LinkedList();   
  }
  
  set width(w) { this.node.style.width = w + "px"; }

  addChild(child) {
    this.children.add(child);
    return this;
  }

  layout() {
    
    var size  = this.children.size;
    var child = this.children.first;
    
    while (size--) {
      child.layout();
      child = child.next;
    }    
  }
  
  resize(event) {    
    
    var w = body.offsetWidth;
    var x = event.clientX;
    
    this.width = clamp(x, 1, w);    
    this.ratio = x / w;
    this.layout();
  }
  
  render() {
    var size  = this.children.size;
    var child = this.children.first;
    
    while (size--) {
      child.render();
      child = child.next;
    }    
  }
  
  update(event) { 
    this.width = body.offsetWidth * this.ratio;
    this.layout();
  }
}

//
// TWEEN
// ===========================================================================
class Tween {
  
  constructor(duration, config) {
        
    this.x = 0;
    this.y = 0;  
    
    this.tween = TweenLite.from(this, duration, config);
  }
}

//
// BOX
// ===========================================================================
class Box {

  constructor(node, config = {}) {

    this.node = node;    
    
    TweenLite.set(node, config);

    this.x = this.node.offsetLeft;
    this.y = this.node.offsetTop;
    
    this.tweens = new LinkedList();
  }
  
  layout() {
    
    var x  = this.x;
    var y  = this.y;    
    
    this.x = this.node.offsetLeft;
    this.y = this.node.offsetTop;
        
    if (x === this.x && y === this.y) return this;   
        
    var dx = x - this.x;
    var dy = y - this.y;
        
    var tween = new Tween(duration, { 
      x: dx, 
      y: dy, 
      ease, 
      onComplete: () => this.removeTween(tween) 
    });
       
    if (!this.tweens.size) {
      TweenLite.set(this.node, { x: dx, y: dy });
    }
    
    this.tweens.add(tween);
    
    return this;
  }

  removeTween(tween) {
    this.tweens.remove(tween);    
    return this;
  }

  render() {

    var size = this.tweens.size;

    if (!size) return;
 
    var tween = this.tweens.first;   

    var x = 0;
    var y = 0;
        
    while (size--) {
      x += tween.x;
      y += tween.y;
      tween = tween.next;
    }

    TweenLite.set(this.node, { x, y });
    return this;
  }
}

//
// LINKED LIST
// ===========================================================================
// class LinkedList {

//   constructor() {

//     // Alias
//     this.add = this.append;
//     this.clear();
//   }

//   get isEmpty() { return !this.size && !this.first && !this.last; }

//   static fromArray(array) {

//     var list = new LinkedList();
//     var size = array.length;

//     while (size--) list.prepend(array[size]);
//     return list;
//   }

//   clear() {

//     this.size  = 0;
//     this.first = null;
//     this.last  = null;
//     this.next  = null;
//     this.prev  = null;

//     return this;
//   }

//   get(i) {

//     if (this.isEmpty) return null;

//     var node = this.first;
//     var size = i % this.size;

//     while (size--) node = node.next;
//     return node;
//   }

//   random() {

//     var n = Math.random() * this.size >> 0;
//     return this.get(n);
//   }

//   toArray() {

//     var array = [];
//     var node  = this.first;
//     var size  = this.size;

//     while (size--) {
//       array.push(node);
//       node = node.next;
//     }

//     return array;
//   }

//   forEach(callback, scope) {

//     var node = this.first;
//     var size = this.size;

//     for (var i = 0; i < size; i++) {
//       callback.call(scope, node, i);
//       node = node.next;
//     }
//   }

//   append(node) {

//     if (this.first === null) {

//       node.prev = node;
//       node.next = node;

//       this.first = node;
//       this.last  = node;
//       this.next  = node;

//     } else {

//       node.prev = this.last;
//       node.next = this.first;

//       this.last.next = node;
//       this.last      = node;
//     }

//     this.size++;
//     return node;
//   }

//   prepend(node) {

//     if (this.first === null) {

//       return this.append(node);

//     } else {

//       node.prev = this.last;
//       node.next = this.first;

//       this.first.prev = node;
//       this.last.next  = node;
//       this.first      = node;
//     }

//     this.size++;
//     return node;
//   }

//   remove(node) {

//     if (this.size > 1) {

//       node.prev.next = node.next;
//       node.next.prev = node.prev;

//       if (node === this.first) this.first = node.next;
//       if (node === this.last)  this.last = node.prev;

//     } else {

//       this.first = null;
//       this.last  = null;
//     }

//     node.prev = null;
//     node.next = null;

//     this.size--;    
//     return node;
//   }

//   insertBefore(node, newNode) {

//     newNode.prev = node.prev;
//     newNode.next = node;

//     node.prev.next = newNode;
//     node.prev      = newNode;

//     if (newNode.next === this.first) this.first = newNode;

//     this.size++;
//     return newNode;
//   }

//   insertAfter(node, newNode) {

//     newNode.prev = node;
//     newNode.next = node.next;

//     node.next.prev = newNode;
//     node.next      = newNode;

//     if (newNode.prev === this.last) this.last = newNode;

//     this.size++;
//     return newNode;
//   }
// }

function clamp(value, min, max) {
  return value < min ? min : (value > max ? max : value);
}

function createElement(type, parent) {
  var node = document.createElement(type);
  parent && parent.appendChild(node);
  return node;
}

// ===========================================================================
var $   = document.querySelector.bind(document);
var $$  = document.querySelectorAll.bind(document);
var log = console.log.bind(console);

var body = document.body;
var ease = new CustomEase(10, 0.9);
var size = 256;

var duration  = 1;

demo();









View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/TweenMax.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/utils/Draggable.min.js
  3. https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/SplitText.min.js
  4. https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/LinkedList2.js