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

              
                <div class="healthy-development">
        <div class="things-container">
          <div class="development-things">
            Things I need ...
          </div>
          <div class="development-things">
            Things I don't need ...
          </div>
          <div id="Dev_1" class="things-needed need">
          </div>
          <div id="NonDev_1" class="things-needed dont-need">
          </div>
          <div id="Dev_2" class="things-needed need">
          </div>
          <div id="NonDev_2" class="things-needed dont-need">
          </div>
          <div id="Dev_3" class="things-needed need">
          </div>
          <div id="NonDev_3" class="things-needed dont-need">
          </div>
          <div id="Dev_4" class="things-needed need">
          </div>
          <div id="NonDev_4" class="things-needed dont-need">
          </div>
          <div id="Dev_5" class="things-needed need">
          </div>
          <div id="NonDev_5" class="things-needed dont-need">
          </div>
        </div>
        <div class="child-needs">
          <div id="Toy_car" class="child-things not-needed">
            Toy car
          </div>
          <div id="Food" class="child-things needed">
            Food
          </div>
          <div id="House" class="child-things needed">
            House
          </div>
          <div id="Umbrella" class="child-things not-needed">
            Umbrella
          </div>
          <div id="Desk" class="child-things not-needed">
            Desk
          </div>
          <div id="Clothes" class="child-things needed">
            Clothes
          </div>
          <div id="Television" class="child-things not-needed">
            Television
          </div>
          <div id="Play" class="child-things needed">
            Play
          </div>
          <div id="Rest" class="child-things needed">
            Rest
          </div>
        </div>
      </div>
              
            
!

CSS

              
                pale-teal = #D5F6F6
light-teal = #A4D8D8
child-yellow = #efab2b
dark-teal = #157678
dark-green = #0B3F3F
marker-purple = #7e57c2

.healthy-development
  display flex
  position relative
  flex 0 1 100%
  flex-wrap wrap
  justify-content center
  height 80vh

  .things-container
    margin-top 2em
    position relative
    width 80%
    display grid
    grid-template-columns:1fr 1fr;
    grid-template-rows:  1fr 1fr 1fr  1fr 1fr 1fr  ;
    height 53vh
    border 2px solid dark-green
    > div
      padding 0.5em
      font-size 1.6em
      text-align center
      border 2px solid dark-green
      background-color rgba(pale-teal, 0.8)
    .development-things
      color white
      background-color dark-teal
    .addRed
      background-color rgb(248, 164, 164)
    .occupied
      background-color #91db4a
      
  .child-needs
    display flex
    height 25vh
    flex 0 1 80%
    flex-wrap wrap
    justify-content space-around
    .child-things
      flex 0 1 10%
      height 1.5em
      font-family: "Poppins-Light", sans-serif
      font-size 1.4em
      color light-navy
      background-color white
      margin 0.5em
      padding 0.25em 1.5em 0.25em 0.75em
      border-radius 0.75em
      box-shadow 0px 7px 15px rgba(0,0,0,0.5)
    .dragging-it
      background-color child-yellow
      font-family "Poppins-Bold", sans-serif
      color light-navy
    .thats-correct
      background-color #609131
      font-family "Poppins-Bold", sans-serif
      color white
    .connected
      background-color child-yellow

              
            
!

JS

              
                let targets = $(".things-needed"); // Table targets

// The drag-n-drop buttons

var buttons = $(".child-things"); // drag buttons

// ------------------------------------------------------------

$.each(buttons, function(i, e) {
  var position = $(e).offset();
  e.originalLeft = position.left - 8;
  e.originalTop = position.top - 8;
});

$.each(buttons, function(i, e) {
  TweenLite.set(e, { position: "absolute", left: e.originalLeft, top: e.originalTop });
});

var overlapThreshold = "50%";

/*
  Draggable works by anchoring the buttons on the IDs of the targets. Without IDs, in the case
  where you are using classes to getElement, Draggable will not work.
 */

Draggable.create(buttons, {
  bounds: ".healthy-development",
  edgeResistance: 0.65,
  type: "x,y",
  throwProps: true,

  onDragStart: function(e) {
    if (e.target.targetAttachedTo) e.target.targetAttachedTo.removeClass("occupied");
  },
  // changes the colour of the targets whilst dragging to give feedback that a
  // dragged object is going to snap to it
  onDrag: function(e) {
    for (let i = 0; i < targets.length; i++) {
      if (this.hitTest(targets[i], overlapThreshold)) {
        $(targets[i]).addClass("addRed");
      } else {
        $(targets[i]).removeClass("addRed");
      }
    }
    $(this.target).addClass("dragging-it");
  },

  // Refactored
  onDragEnd: function(e) {
    let snapMade = false;
    // onRelease of the dragged button
    let theDragged = this.target;
    let theButton = this.target.id;
   
    /*  The next staement is what needs to be used in order 
    to target an element using classses only. */
    
    // let theSpot = document.getElementsByClassName("addRed")[0];
    
    let theSpot = document.getElementById("Dev_1");

    $(theDragged).removeClass("dragging-it");
    if (this.hitTest(theSpot, overlapThreshold) && theButton) {

      let p = $(theSpot).position();
      // tween onto target
      TweenLite.to(`#${theButton}`, 0.1, {
        left: p.left,
        top: p.top,
        x: 110,
        y: 30
      });
      $(theSpot).addClass("occupied");
      e.target.targetAttachedTo = theSpot;
      snapMade = true;
      $(theDragged).addClass("thats-correct");
      
    } else {
      TweenLite.to(theDragged, 0.1, {
        x: 0,
        y: 0,
        top: theDragged.originalTop,
        left: theDragged.originalLeft
      });
    }
  }
});

              
            
!
999px

Console