Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <h1>Draggable: Multiple targets</h1><hr>

<div id="container">
  <div id="box1" class="box">Martin Hughes</div>
  <div id="box2" class="box">Dominic Smith</div>
  <div id="box3" class="box">James Vicary</div>
  <div id="box4" class="box">Josh Sanderson</div>
  <div id="box5" class="box">Joe Bloggs</div>
  <div id="box6" class="box">John Smith</div>
</div>
<div style="width:900px; float:right;">
<div id="dropArea1" class="drop-zone">Tighthead Prop</div>
<div id="dropArea2" class="drop-zone">Hooker</div>
<div id="dropArea3" class="drop-zone">Loosehead Prop</div>
</div>
<div style="width:780px; float:right;">
<div id="dropArea4" class="drop-zone">Second Row</div>
<div id="dropArea5" class="drop-zone">Second Row</div>
</div>
<div style="width:900px; float:right">
<div id="dropArea6" class="drop-zone">Blindside Flanker</div>
<div id="dropArea8" class="drop-zone">Number 8</div>
<div id="dropArea7" class="drop-zone">Openside Flanker</div>
</div>
<div style="width:780px; float:right;">
<div id="dropArea9" class="drop-zone">Scrum Half</div>
<div id="dropArea10" class="drop-zone">Fly Half</div>
</div>
<div style="width:780px; float:right;">
<div id="dropArea12" class="drop-zone">Inside Centre</div>
<div id="dropArea13" class="drop-zone">Outside Centre</div>
</div>
<div style="width:900px; float:right;">
<div id="dropArea14" class="drop-zone">Winger</div>
<div id="dropArea15" class="drop-zone">Full Back</div>
<div id="dropArea11" class="drop-zone">Winger</div>
</div>
              
            
!

CSS

              
                body {
  background-color:black;
  color: #ccc;
	font-family: Signika Negative, Asap, sans-serif;
	font-weight: 300;
  padding: 10px;
}
h1 {
  font-size:40px;
  font-weight: 300;
  color:white;
  margin: 0;
}
#container {
  float:left;
  width: 240px;
  margin: 5px;
}

.box {
  width: 160px;
  height: 60px;
  text-align: center;
  line-height: 60px;
  font-size: 20px;
  color: white;
  border-radius:10px;
  border: 2px solid black;
  background-color: red;
  margin: 5px;
}

a {
  color: white;
}
.highlight {
  width: 160px;
  height: 60px;
  line-height: 60px;
  background-color: green;
}
code {
  color: white;
  font-size:1.2em;
}

#dropArea1, #dropArea2, #dropArea3, #dropArea4, #dropArea5, #dropArea6, #dropArea7, #dropArea8, #dropArea9, #dropArea10, #dropArea11, #dropArea12, #dropArea13, #dropArea14, #dropArea15 {
  width:180px;
  height:80px;
  margin: 0 auto;
  display: inline-block;
  background:#ccc;
  left:600px;
  color:black;
  margin: 15px;
}
              
            
!

JS

              
                
var droppables = $(".box");
var dropZones = $(".drop-zone");

var overlapThreshold = "80%";

droppables.each(initDroppable);

function initDroppable(i, element) {
  
  var insideZone = false;
  
  var highlightAnimation = TweenLite.to(element, 0.3, {
    backgroundColor: "green",
    paused: true
  });
  
  Draggable.create(element, {
    onDrag: function() {
      
      insideZone = false;
      
      for (var i = 0; i < dropZones.length; i++) {
        if (this.hitTest(dropZones[i], overlapThreshold)) {
          insideZone = true;
          break;
        }
      }
      
      if (insideZone) {
        highlightAnimation.play();
      } else {
        highlightAnimation.reverse();
      }
    },
    onDragEnd: function() {
      
      if (!insideZone) {
        TweenLite.to(this.target, 0.2, { 
          x: 0, 
          y: 0 
        });
      }
    }
  });
}

// Draggable.create(droppables, {
//   onDrag: function(e) {
//     if (this.hitTest(dropArea1,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//     else if (this.hitTest(dropArea2,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea3,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea4,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea5,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea6,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea7,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea8,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea9,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea10,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea11,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea12,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea13,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea14,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//         else if (this.hitTest(dropArea15,overlapThreshold)) {
//       $(this.target).addClass("highlight");
//     }
//     else {
//       $(this.target).removeClass("highlight");
//     }
//   },
// onDragEnd: function(e) {
//   //instead of doing hitTest again, just see if it has the highligh class.
//   if (!$(this.target).hasClass("highlight")) {
//     //if there isn't a highlight, send it back to starting position
//     TweenLite.to(this.target, 0.2, {
//       x: 0,
//       y: 0
//     });
//   }

// }
// });
              
            
!
999px

Console