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

              
                <div class="healthy-development">
          <div class="things-container">
            <div class="things-needed">
              Picture
            </div>
            <div class="things-needed">
              Name of the game
            </div>
            <div class="things-needed">
              What you use to play the game
            </div>
            <div class="game-letter">a</div>
            <div class="answered-targets game-name">
              <div id="Racing" class="answered-buttons">
                Racing
              </div>
            </div>
            <div class="answered-targets game-tool">
              <div id="Hurdles" class="answered-buttons">
                Hurdles
              </div>
            </div>
            <div class="game-letter">b</div>
            <div class="game-box game-name"></div>
            <div class="game-box game-tool"></div>
            <div class="game-letter">c</div>
            <div class="game-box game-name"></div>
            <div class="game-box game-tool"></div>
            <div class="game-letter">d</div>
            <div class="game-box game-name"></div>
            <div class="game-box game-tool"></div>
            <div class="game-letter">e</div>
            <div class="game-box game-name"></div>
            <div class="game-box game-tool"></div>
            <div class="game-letter">f</div>
            <div class="game-box game-name"></div>
            <div class="game-box game-tool"></div>
          </div>
          <div class="game-answers">
            <div id="Hula" class="game-things games">
              Hula hoop
            </div>
            <div id="Swimming" class="game-things games">
              Swimming
            </div>
            <div id="Singing" class="game-things games">
              Singing game
            </div>
            <div id="Football" class="game-things games">
              Football
            </div>
            <div id="Somersault" class="game-things games">
              Somersault
            </div>
            <div id="Handkerchief" class="game-things tools">
              Handkerchief
            </div>
            <div id="Ball" class="game-things tools">
              Ball
            </div>
            <div id="Hoop" class="game-things tools">
              Hoop
            </div>
            <div id="Floaters" class="game-things tools">
              Floaters
            </div>
            <div id="Mattress" class="game-things tools">
              Mattress
            </div>
          </div>
        </div>
              
            
!

CSS

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

.healthy-development
  display flex
  position relative
  flex 0 1 100%
  flex-wrap wrap
  justify-content center
  height 65vh
 
.things-container
  width 80%
  display grid
  grid-template-columns:0.3fr 1fr 1fr;
  grid-template-rows:  1fr 1fr 1fr 1fr 1fr 1fr 1fr ;
  height 30em
  border 2px solid dark-green
  border-bottom 0
  .game-box, .game-letter, .things-needed, .answered-targets
    padding 0.4em 0 0.3em
    font-size 1.4em
    text-align center
    border 2px solid dark-green
    background-color rgba(pale-teal, 0.8)
    .answered-buttons
      width 5em
      height 1.5em
      font-family: "Poppins-Semi-Bold", sans-serif
      font-size 1em
      color white
      background-color correct-green
      margin-left 0.25em
      padding 0.25em 1.2em 0.2em 0
      border-radius 0.5em
      box-shadow 0px 7px 15px rgba(0,0,0,0.5)
  .answered-targets
    padding 0
  .addRed
    background-color rgb(248, 164, 164)
  .occupied
    background-color #91db4a
  .things-needed
    color white
    background-color dark-teal
  

.game-answers
  display flex  
  flex 0 1 100%
  height 3.5em
  flex-wrap wrap
  justify-content space-around
  height 15vh
  .game-things
    width 7.5em
    height 1.5em
    font-family: "Poppins-Light", sans-serif
    font-size 1.3em
    color light-navy
    background-color white
    margin 0.4em
    padding 0.25em 1.5em 0.25em 0.75em
    border-radius 0.75em
    box-shadow 0px 7px 15px rgba(0,0,0,0.5)
  #Ball
    width 2em
  #Hoop
    width 2.5em
  #Love
    width 2.5em
  #Racing
    width 4em
  #Football, #Floaters, #Mattress
    width 4.5em
  #Swimming, #Hula, #Television
    width 5.5em
  #Somersault
    width 6em
  #Handkerchief
    width 7em
  .dragging-it
    background-color child-yellow
    font-family "Poppins-Bold", sans-serif
    color light-navy
  .thats-correct
    background-color correct-green
    font-family "Poppins-Semi-Bold", sans-serif
    color white
  .connected
    background-color child-yellow
              
            
!

JS

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

let childrenGames = {
  "Racing": "Hurdles",
  "Football": "Ball",
  "Hula hoop": "Hoop",
  "Singing game": "Handkerchief",
  "Somersault": "Mattress",
  "Swimming": "Floaters"
}

/* Dragging buttons function */
// The drag-n-drop targets

let targets = $(".game-box"); // Table targets

// The drag-n-drop buttons

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

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

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

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

let neededThings = 0;
var overlapThreshold = "50%";

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

  onDragStart: function() {
    if (this.target.targetAttachedTo) this.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() {
    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");
  },

  onDragEnd() {

    let theDragged = this.target;
    let theSpot = document.querySelector(".addRed");
    let isHitting = false;

    if (theSpot && this.hitTest(theSpot, overlapThreshold)) {
      isHitting = true;
    }

    $(theDragged).removeClass("dragging-it");
    if (isHitting) {
      if ($(theDragged).hasClass("games") && $(theSpot).hasClass("game-name") ||
        $(theDragged).hasClass("tools") && $(theSpot).hasClass("game-tool")) {
        // if the tool is the one used for the game || if the game is the one that played with the tool
        
        let p = $(theSpot).position();
        // tween onto target
        TweenLite.to(theDragged, 0.1, {
          left: p.left,
          top: p.top,
          x: 0,
          y: -5
        });
        $(theSpot).addClass("occupied");
        theDragged.targetAttachedTo = theSpot;
        snapMade = true;
        $(theDragged).addClass("thats-correct");
        neededThings++;
        if (neededThings == 9) {
          setTimeout(() => {
            functions.challengeFinished.play();
          }, 2000);
        }
      } else if ($(theDragged).hasClass("games") && $(theSpot).hasClass("game-tool") ||
        $(theDragged).hasClass("tools") && $(theSpot).hasClass("game-name")) {
        TweenLite.to(theDragged, 0.1, {
          x: 0,
          y: 0,
          top: theDragged.originalTop,
          left: theDragged.originalLeft
        });
        notCorrect.play();
      }
    } else {
      TweenLite.to(theDragged, 0.1, {
        x: 0,
        y: 0,
        top: theDragged.originalTop,
        left: theDragged.originalLeft
      });
     
    }
  }
});
              
            
!
999px

Console