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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 ng-app="dragDrop" ng-controller="DragDropController">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <p class="h2">{{ message }}</p>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-4" ng-repeat="bin in [1, 2, 3]">
                <div id="bin{{ bin }}" class="bin" bin="bin" droppable drop="handleDrop">{{ bin }}</div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-4" ng-repeat="item in [1, 2, 3]">
                <div id="item{{ item }}" class="item" draggable item="item">{{ item }}</div>
            </div>
        </div>
    </div>
</body>
              
            
!

CSS

              
                .h2 {
  margin-bottom: 2em;
  text-align: center;
}
%content {
  font-size: 32px;
  text-align: center;
  margin: 0 5px;
}
.bin, .item {
  @extend %content;
  margin: 10px;
  padding: 10px;
  min-height: 150px;
  min-width: 150px;
}
.bin {
  border: 1px solid red;
}
.item {
  background: blue;
  color: white;
  cursor: move;
  transition: all 0.2s ease;
}
.drag {
  opacity: 0.5;
}
.over {
  background: red;
}
              
            
!

JS

              
                (function() {
    "use strict";
    var app = angular.module('dragDrop', []);

    app.directive('draggable', function() {
        return function(scope, element) {
            // this gives us the native JS object
            var el = element[0];

            el.draggable = true;

            el.addEventListener(
                'dragstart',
                function(e) {
                    e.dataTransfer.effectAllowed = 'move';
                    e.dataTransfer.setData('Text', this.id);
                    this.classList.add('drag');
                    return false;
                },
                false
            );

            el.addEventListener(
                'dragend',
                function(e) {
                    this.classList.remove('drag');
                    return false;
                },
                false
            );
        }
    });

    app.directive('droppable', function() {
        return {
            scope: {
                drop: '&',
                bin: '='
            },
            link: function(scope, element) {
                // again we need the native object
                var el = element[0];

                el.addEventListener(
                    'dragover',
                    function(e) {
                        e.dataTransfer.dropEffect = 'move';
                        // allows us to drop
                        if (e.preventDefault) e.preventDefault();
                        this.classList.add('over');
                        return false;
                    },
                    false
                );

                el.addEventListener(
                    'dragenter',
                    function(e) {
                        this.classList.add('over');
                        return false;
                    },
                    false
                );

                el.addEventListener(
                    'dragleave',
                    function(e) {
                        this.classList.remove('over');
                        return false;
                    },
                    false
                );

                el.addEventListener(
                    'drop',
                    function(e) {
                        // Stops some browsers from redirecting.
                        if (e.stopPropagation) e.stopPropagation();

                        this.classList.remove('over');

                        var binId = this.id;
                        var item = document.getElementById(e.dataTransfer.getData('Text'));
                        this.appendChild(item);
                        // call the passed drop function
                        scope.$apply(function(scope) {
                            var fn = scope.drop();
                            if ('undefined' !== typeof fn) {
                                fn(item.id, binId);
                            }
                        });

                        return false;
                    },
                    false
                );
            }
        }
    });

    app.controller('DragDropController', function($scope) {
        $scope.message = 'drag the blue items over white spaces';
        $scope.handleDrop = function(item, bin) {
            $scope.message = 'Item ' + item + ' has been dropped into ' + bin;
        }
    });
}());
              
            
!
999px

Console