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

              
                <html ng-app="ionicApp">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

  <title>Ionic Template</title>

  <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
  <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/utils/Draggable.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/plugins/CSSPlugin.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenLite.min.js"></script>
</head>

<body ng-controller="MyCtrl">
  <ion-header-bar class="bar-stable">
    <h5 class="title" >  </h5>
    
    <button ng-click="restartClicked()" class="button button-small button-left  icon button-icon ion-refresh">
      reset
      <!--style="color:rgba(94, 5, 2, 0.67)">-->
    </button>
  </ion-header-bar>
  <ion-content scroll=false>
    <my-board class="board" id="container">
      <div style="padding:0px" class="row">
        <div class="col col-20 left-panel">
          
              
          
         
         <div style="position:relative" type="blue" my-draggable></div>
          <div style="position:relative" type="green" my-draggable></div>
          <div style="position:relative" type="yellow" my-draggable></div>
          <div style="position:relative" type="black" my-draggable></div>

        </div>
        <div class="col col-35 ">
          <drop-zone id="blue"></drop-zone>
          <drop-zone id="yellow"></drop-zone>
        </div>
        <div class="col col-35 ">
          <drop-zone id="green"></drop-zone>
          <drop-zone id="black"></drop-zone>
        </div>
        <div class="col col-10 ">
        </div>
      </div>
    </my-board>
  </ion-content>
</body>

</html>
              
            
!

CSS

              
                body {

}
.bar .title{
  font-size: 14px !important;
  text-align: left;
}
.invite {
    border: 1px  solid #a2d793;
    background-color: #a2d793 !important;
    -webkit-box-shadow: -8px 9px 3px 2px #468c00;
    -moz-box-shadow: -8px 9px 3px 2px #468c00;
    box-shadow: -8px 9px 3px 2px #468c00;
}
.drag-square-large {
    float:left;
    position: absolute;
    width:60%;
    padding-bottom : 60%;  //= width for a 1:1 aspect ratio;
    margin:2%;
    background-position:center center;
    background-repeat:no-repeat;
    background-size:contain; //you change this to "contain" if you don't want the images to be cropped
    border-radius: 10px;
    color: transparent;
     
   
   

}
.bar.bar-stable{
   background-color: #749EA2 !important;
}
.black{
	 background-image: url("https://placeholdit.imgix.net/~text?txtsize=20&bg=000000&txt=Black&w=60&h=60&txttrack=0");
}

.blue{
	 background-image: url("https://placeholdit.imgix.net/~text?txtsize=20&bg=00008b&txt=Blue&w=60&h=60&txttrack=0");
}
.green{
	 background-image: url("https://placeholdit.imgix.net/~text?txtsize=20&bg=006400&txt=Green&w=60&h=60&txttrack=0");
}
.yellow{
	 background-image: url("https://placeholdit.imgix.net/~text?txtsize=18&bg=ffff00&txt=Yellow &w=60&h=60&txttrack=0");
}
.board {
    min-height: 100%;
    display: flex;
    flex-direction: row;
    display: -webkit-box;
    display: -webkit-flex;
    //background-color:#CF641B;
  background-color:#749EA2;
}

.left-panel{
    border-right: solid  2px #000000;
}

.drop-header-small {
    min-height: 50px;
	  position: inherit !important;
}
.drop-card-header {
    font-size: 2.0vw;
    white-space: normal;
}
.drop-square-small {
    float:left;
		position: inherit !important;
    width: 100%;
    padding-bottom : 35% !important; /* = width for a 1:1 aspect ratio */
    margin:0%;
    background-color: #ffffff;
    background-position:center center;
    background-repeat:no-repeat;
    background-size: auto; 
    
}
.shadow-card{
    -webkit-box-shadow: -8px 9px 3px 2px rgba(0,0,0,0.57);
  
    box-shadow: -8px 9px 3px 2px rgba(0,0,0,0.57) !important;
    border: 5px #000333;
    margin: 5%;
    border-radius: 12px !important;
    border-bottom-right-radius: 8px;
    width: 95%;
    overflow-x: visible;
    //background-color: transparent;
    //border:.5px solid #384352;


}
              
            
!

JS

              
                angular.module('ionicApp', ['ionic'])

.controller('MyCtrl', function($scope, $rootScope) {
    $scope.restartClicked = function() {
      $rootScope.$emit("resetBoard");
    }
  })
  /*******************************************************************
   * Drag and drop manager directive 
   *********************************************************************/
  .directive('myBoard', function($rootScope) {
    return {
      scope: {
        image: '='
      },
      ransclude: true,
      restrict: 'EA',
      controller: function($scope) {
        var dropZones = {};
        var dragItems = []
        var overlapThreshold = "50%";
        this.addDragItem = function(dragItem) {
          dragItems.push(dragItem);
        };
        /****************************************************************
         * Registers dropZone items to the manager
         * @param   Object   drop zone scope obect
         *****************************************************************/
        this.addDropZone = function(dz) {
          dropZones[dz.id] = dz;
        };

        /****************************************************************
         * Handles dragging of drag item relative to drop areas
         *****************************************************************/
        this.handleDrag = function(draggable) {
          var dz = dropZones[draggable.vars.modelType];
          if (Draggable.hitTest(draggable.vars.element, dz.element, overlapThreshold)) {
            console.log("draggable.x and draggable.y:", draggable.x, draggable.y, "draggable.pinterX,draggable.pinterY:",
              draggable.pointerX, draggable.pointerY, "dz.element.x:", dz);
            dz.invite();
          } else {
            dz.uninvite();
          }
        };

        /****************************************************************
         * Handles release of drag item relative to drop areas
         * @param   Draggable  draggabele
         *****************************************************************/
        this.handleDrop = function(draggable) {
          var dz = dropZones[draggable.vars.modelType];
          if (draggable.hitTest(dz.element, overlapThreshold)) {
            draggable.land(dz);
            dz.uninvite();
          } else {
            draggable.reset();
          }

        }

        /****************************************************************
         * listens for "boardReset" event 
         *****************************************************************/
        $rootScope.$on("resetBoard", function() {
          resetBoard();
        })

        /******************************************************************
         * Callback for "resetBoard" event 
         * returns all drag items and drop zones back to their original states
         *******************************************************************/
        function resetBoard() {
          dragItems.forEach(function(dragItem) {
            dragItem.reset();
          })
        }

      },
      link: function postLink(scope) {},
    };
  })
  /****************************************************************
   * Directive representing draggable item 
   *****************************************************************/
  .directive('myDraggable', function() {
    return {
      scope: {
        image: '=',
        type: '@'
      },
      restrict: 'EA',
      require: '^myBoard',
      link: function postLink(scope, element, attrs, boardController) {
        var dragElement = element[0];
        var d = Draggable.create(dragElement, {
          type: 'x,y',
          bounds: '#container',
          element: dragElement.children[0],
          modelType: scope.type,
          zIndexBoost: true

        })[0];
        
        /*******************************************************************
         * "lands" the draggable item on the given drop zone's "langing area"
         * @param   {HTMLElement}   element
         *****************************************************************/
        Draggable.prototype.land = function(zropZone) {
          console.log("landing", this.vars.modelType);
          this.applyBounds(zropZone.landingZone);
          TweenLite.to(this.target, 0.4, {
            scale: 0.5,
            //rotation: "+=720",
            x: this.x,
            y: this.y
          });
          this.disable();

        };
        /****************************************************************
         * Resets the draggable item back to the original state/ position
         * 
         *****************************************************************/
        Draggable.prototype.reset = function() {
          console.log("reseting", this.vars.modelType);
          this.applyBounds('#container');
          TweenLite.to(this.target, 0.4, {
            scale: 1,
            //rotation: "+=360",
            x: 0,
            y: 0
          });
          this.enable();

        };

        /****************************************************************
         * Call back for onRelaese  event
         *****************************************************************/

        function onRelease() {
          //console.log("You dropped the ball!");
          boardController.handleDrop(d);
        }

        /****************************************************************
         * Call back for onRelaese  event
         *****************************************************************/
        function onDrag() {
          //console.log("Dragging: quit dragging me around!");
          /*TweenLite.to(d.target, 0, {
            x: d.pointerX,
            y: d.pointerY
          });*/
          boardController.handleDrag(d);
        }

        d.addEventListener("drag", onDrag);
        d.addEventListener("release", onRelease);

        boardController.addDragItem(d);

      },
      controller: function($scope) {},
      template: "<div id=\"drag\"   class=\"drag-square-large {{type}}\"></div>"
    };
  })

/****************************************************************
 * Directive representing drop zone area 
 *****************************************************************/
.directive('dropZone', function() {
  return {
    scope: {
      id: "@"
    },
    restrict: 'EA',
    require: '^myBoard',
    link: function postLink(scope, el, attrs, boardController) {
      scope.dz = {
        element: el[0],
        landingZone: el.find('land-zone')[0],
        id: scope.id,
        /****************************************************
         * Displays a visual indcator (invitation) on dropable areas
         *****************************************************/
        invite: function() {
          scope.dz.landingZone.classList.add('invite');
        },
        /**********************************************************
         * Removes a visual indcator  (invitation) from dropable areas 
         * called as the user moves away from the "acceptable" drop area
         ************************************************************/
        uninvite: function() {
          scope.dz.landingZone.classList.remove('invite');
        }
      }
      boardController.addDropZone(scope.dz);

    },

    /* jshint ignore:start */
    template: "<div class=\"card shadow-card\">\
								<div  class=\"item item-divider drop-header-small\">\
										<div  class=\"drop-card-header \">{{id}}</div>\
								</div>\
               <land-zone class=\"item item-image drop-square-small\" >\
							</land-zone>\
							 </div>"
  };
});
              
            
!
999px

Console