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

              
                <body>
  <div id="demo">
  <div id="letter-box">
    <div id="container">
      <div id="scroll-box">      
      <!--
        <div class="letter"><div>A</div></div>
        <div class="letter"><div>B</div></div>
        <div class="letter"><div>C</div></div>
        <div class="letter"><div>D</div></div>
        <div class="letter"><div>E</div></div>
        <div class="letter"><div>F</div></div>
        <div class="letter"><div>G</div></div>
        <div class="letter"><div>H</div></div>
        <div class="letter"><div>I</div></div>
        <div class="letter"><div>J</div></div> 
        <div class="letter"><div>K</div></div>
        <div class="letter"><div>L</div></div>
        <div class="letter"><div>M</div></div>
        <div class="letter"><div>N</div></div>
        <div class="letter"><div>O</div></div>
        <div class="letter"><div>P</div></div>
        <div class="letter"><div>Q</div></div>
        <div class="letter"><div>R</div></div>  -->
        <div class="letter"><div>S</div></div>
        <div class="letter"><div>T</div></div>
        <div class="letter"><div>U</div></div>
        <div class="letter"><div>V</div></div>       
        <div class="letter"><div>W</div></div>
        <div class="letter"><div>X</div></div>
        <div class="letter"><div>Y</div></div> 
        <div class="letter"><div>Z</div></div>      
      </div>
    </div>
  </div>
  <!--
  <div class="middle">
    <img src="img/soep.jpg" alt="ik ben de soep" id="soep">
  </div>
  -->
  <div id="containersoep" class="soepcontainer">
    <img id="soep" src="http://www.wloman.com/admin-panel/images/freshproduct/1418472463beefTom.jpg" alt="ik ben de soep">
  </div>
  <br>
  <br>
  <br>
  <br>
  <br>
  <div id="end-zone"></div>
</div>
              
            
!

CSS

              
                body {
  background-color: #eee;
  height: 100vh;
  margin: 0;
  position: relative;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

#demo {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
}

#end-zone {
  height: 200px;
  background: rgb(134, 205, 191);
  padding: 10px;
  margin: 10px;
  box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.3);
}

.middle {
  flex: 1;
}

#letter-box {
  margin: 10px;
  padding: 10px;
  background-color: white;
  box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.3);
}

#container {
  border: 1px solid #ccc;
  position: relative;
}

#scroll-box {
  white-space: nowrap;
  overflow-x: scroll;
}

.letter {
  width: 80px;
  height: 80px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.letter > div,
.cloned-letter {
  background-color: mediumvioletred;
  color: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  position: relative;
  width: 60px;
  height: 60px;
  cursor: move;
  box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.5);
}

.cloned-letter {
  position: absolute;
}

#soep {
  text-align: center;
}

.soepcontainer 
{
}
              
            
!

JS

              
                
NodeList.prototype.forEach = Array.prototype.forEach;

var container = document.getElementById("container");
var startZone = document.getElementById("scroll-box");
var endZone   = document.getElementById("end-zone");
var letters   = document.querySelectorAll(".letter > div");
var soepZone  = document.getElementById("containersoep"); 
var threshold = "70%";

var containerBounds = container.getBoundingClientRect();
var letterItems = [];

letters.forEach(function(letter, index) 
{  
  var clone = letter.cloneNode(true);
  var letterItem = 
  { element: letter, 
    clone: clone, 
    wrapper: letter.parentNode,
    zone: "startZone" };
  
  clone._index = index;
  clone.className = "cloned-letter";
  TweenLite.set(clone, { autoAlpha: 0, scale: 0, x: 0, y: 0 });
  container.insertBefore(clone, container.firstChild);
    
  letterItems.push(letterItem);
  
  letter.onmousedown = function(event) {
    var letterBounds = letter.getBoundingClientRect();

    letterItem.x = letterBounds.left - containerBounds.left;
    letterItem.y = letterBounds.top  - containerBounds.top;

    TweenLite.set(letter, { scale: 0, autoAlpha: 0 });
    TweenLite.set(clone, { x: letterItem.x, y: letterItem.y, zIndex: 1000, autoAlpha: 1, scale: 1 });
    startDraggable(event, letterItem);
  }
});

function startDraggable(event, letter) {
  var clone = letter.clone;
  var wrapper = letter.wrapper;
  var draggable = Draggable.get(clone);
  
  if (!draggable) 
  {
    draggable = new Draggable(clone, { onDragEnd: onDragEnd }); 
  }     
  
  draggable.startDrag(event);
  if (letter.zone == "startZone")
  {
    collapseSpace(clone, wrapper);
  }
}

function collapseSpace(clone, wrapper) 
{
  TweenLite.to(clone, 0.15, { scale: 1.2, autoAlpha: 0.75 });  
  TweenLite.to(wrapper, 0.3, { width: 0, backgroundColor:'blue' });
}

function onDragEnd() {  
  var letter = letterItems[this.target._index]; 
  console.log("Zone: " + letter.zone) 
  if (this.hitTest(endZone, threshold))
  {
    console.log("Hit with the Endzone");
    addToEndZone(letter, this.target);
  }
  else if (this.hitTest(container, threshold))
  {
    addToStartZone(letter, this.target);
  }
  else if (this.hitTest(soep, threshold))
  {
    addToSoep(letter, this.target);
  }
  else
  {
    moveBack(letter);
  }
}

function addToEndZone(letter, target) {
  var clone   = letter.clone;
  var wrapper = letter.wrapper;
  var element = letter.element;
  
  endZone.appendChild(wrapper);
  TweenLite.set(wrapper, { width: 80 });
  
  var cloneBounds   = clone.getBoundingClientRect();
  var wrapperBounds = wrapper.getBoundingClientRect();  
  var x = cloneBounds.left - wrapperBounds.left;
  var y = cloneBounds.top  - wrapperBounds.top;
      
  TweenLite.set(clone, { autoAlpha: 0, scale: 0, x: 0, y: 0 });  
  TweenLite.set(element, { x: x, y: y, scale: 1.2, autoAlpha: 0.75 });  
  TweenLite.to(element, 1.3, { scale: 1, autoAlpha: 1, x: 0, y: 0 });

  letterItems[target._index].zone = "endZone";
}

function addToStartZone(letter, target)
{
  var clone   = letter.clone;
  var element = letter.element;
  var wrapper = letter.wrapper;

  startZone.insertBefore(wrapper, startZone.firstChild);
  TweenLite.set(wrapper, { width: 80 });

  var cloneBounds   = clone.getBoundingClientRect();
  var wrapperBounds = wrapper.getBoundingClientRect();  
  var x = cloneBounds.left - wrapperBounds.left;
  var y = cloneBounds.top  - wrapperBounds.top;

  TweenLite.to(wrapper, 0.2, { width: 80, delay: 0 });
  TweenLite.to(clone, 0.3, { scale: 1, autoAlpha: 1, x: letter.x, y: letter.y });
  TweenLite.set(clone, { autoAlpha: 0, scale: 0, x: 0, y: 0, delay: 0.3 });
  TweenLite.set(element, { scale: 1, autoAlpha: 1, delay: 0.3 });

  letterItems[target._index].zone = "startZone";
  console.log("currentZone: " + letterItems[target._index].zone);
}

function addToSoep(letter, target)
{

  if (letterItems[target._index].zone == "soepZone")
  {
    console.log("ik zat al in de soep!");
  }
  else
  {
    console.log("ik zat nog niet in de soep");

    var clone    = letter.clone;
    var element  = letter.element;
    var wrapper  = letter.wrapper;
  
    var cloneX = clone.x;
    var cloneY = clone.y;
  
    soepZone.appendChild(wrapper);
    TweenLite.set(wrapper, { width: 80, x: clone.x, y: clone.y,backgroundColor:'red' });
  
    var cloneBounds   = clone.getBoundingClientRect();
    var wrapperBounds = wrapper.getBoundingClientRect();
    var x = cloneBounds.left - wrapperBounds.left;
    var y = cloneBounds.top - wrapperBounds.top;
  
    TweenLite.set(clone, {autoAlpha: 0, scale: 0, x: x, y: x} );
    TweenLite.set(element, { x: x, y: y, scale: 1.2, autoAlpha: 0.75});
    TweenLite.to(element, 0.5, { scale: 1, autoAlpha: 1, x: cloneX, y: cloneY });
  
    letterItems[target._index].zone = "soepZone";
  }
}

function moveBack(letter) {
  console.log("moveBackToStart");  
  var clone   = letter.clone;
  var element = letter.element;
  var wrapper = letter.wrapper;  
  
  TweenLite.to(wrapper, 0.2, { width: 80, delay: 0 });
  TweenLite.to(clone, 0.3, { scale: 1, autoAlpha: 1, x: letter.x, y: letter.y });
  TweenLite.set(clone, { autoAlpha: 0, scale: 0, x: 0, y: 0, delay: 0.3 });
  TweenLite.set(element, { scale: 1, autoAlpha: 1, delay: 0.3 });
}
              
            
!
999px

Console