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

              
                <div class="container">
	<h1 class="page-header">Native HTML5 Drag and Drop <small>Full Demo</small></h1>
	<div id="columns-full" class="columns clearfix">
		<div class="column" draggable="true"><header>A</header><div class="count" data-col-moves="0"></div></div>
		<div class="column" draggable="true"><header>B</header><div class="count" data-col-moves="0"></div></div>
		<div class="column" draggable="true"><header>C</header><div class="count" data-col-moves="0"></div></div>
		<div class="column" draggable="true"><header>D</header><div class="count" data-col-moves="0"></div></div>
	</div>
	<small>Taken and updated (with the classList API) from <a href="https://www.html5rocks.com/en/tutorials/dnd/basics/">HTML5Rocks</a><br>
		No IE support as it does not support the DataTransfer API.</small>
</div>

              
            
!

CSS

              
                .column {
	background-color: #ccc;
	border-radius: 10px;
	border: 2px solid #666666;
	box-shadow: inset 0 0 3px #000;
	cursor: move;
	float: left;
	height: 150px;
	margin-bottom: 30px;
	margin-right: 5px;
	text-align: center;
	width: 150px;
}

.column header {
	background: linear-gradient(to right, rgb(0,0,0), rgb(79,79,79), rgb(21,21,21));
	border-bottom: 1px solid #ddd;
	border-top-left-radius: 10px;
	border-top-right-radius: 10px;
	box-shadow: 5px;
	color: #fff;
	padding: 5px;
	text-shadow: #000 0 1px;
}

.column {
	transition: transform 0.2s ease-out;
}

.column.over {
	border: 2px dashed #000;
}

.column.moving {
	opacity: 0.25;
	transform: scale(0.8);
}

.column .count {
	font-weight: bold;
	padding-top: 15px;
	text-shadow: #fff 0 1px;
}
              
            
!

JS

              
                // Full example
(function() {
	var id_ = 'columns-full';
	var cols_ = document.querySelectorAll('#' + id_ + ' .column');
	var dragSrcEl_ = null;

	this.handleDragStart = function(e) {
		e.dataTransfer.effectAllowed = 'move';
		e.dataTransfer.setData('text/html', this.innerHTML);

		dragSrcEl_ = this;

		// this/e.target is the source node.
		this.classList.add('moving');
	};

	this.handleDragOver = function(e) {
		if (e.preventDefault) {
			e.preventDefault(); // Allows us to drop.
		}

		e.dataTransfer.dropEffect = 'move';

		return false;
	};

	this.handleDragEnter = function(e) {
		this.classList.add('over');
	};

	this.handleDragLeave = function(e) {
		// this/e.target is previous target element.
		this.classList.remove('over');
	};

	this.handleDrop = function(e) {
		// this/e.target is current target element.

		if (e.stopPropagation) {
			e.stopPropagation(); // stops the browser from redirecting.
		}

		// Don't do anything if we're dropping on the same column we're dragging.
		if (dragSrcEl_ != this) {
			dragSrcEl_.innerHTML = this.innerHTML;
			this.innerHTML = e.dataTransfer.getData('text/html');

			// Set number of times the column has been moved.
			var count = this.querySelector('.count');
			var newCount = parseInt(count.getAttribute('data-col-moves')) + 1;
			count.setAttribute('data-col-moves', newCount);
			count.textContent = 'moves: ' + newCount;
		}

		return false;
	};

	this.handleDragEnd = function(e) {
		// this/e.target is the source node.
		[].forEach.call(cols_, function(col) {
			col.classList.remove('over');
			col.classList.remove('moving');
		});
	};

	[].forEach.call(cols_, function(col) {
		col.setAttribute('draggable', 'true'); // Enable columns to be draggable.
		col.addEventListener('dragstart', this.handleDragStart, false);
		col.addEventListener('dragenter', this.handleDragEnter, false);
		col.addEventListener('dragover', this.handleDragOver, false);
		col.addEventListener('dragleave', this.handleDragLeave, false);
		col.addEventListener('drop', this.handleDrop, false);
		col.addEventListener('dragend', this.handleDragEnd, false);
	});
})();
              
            
!
999px

Console