<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML5-Drag-Demo by 顽Shi</title>
<style>
#columns{
width: 650px;
height: 650px;
}
.column {
box-sizing: border-box;
height: 200px;
width: 200px;
float: left;
border: 1px solid black;
background-color: green;
margin-right: 5px;
text-align: center;
cursor: move;
}
.column header {
color: black;
text-shadow: #000 0 1px;
box-shadow: 5px;
padding: 5px;
background: red;
border-bottom: 1px solid black;
}
.column.over {
border: 3px dashed #000;
}
</style>
</head>
<body>
<div id="columns">
<div class="column" draggable="true"><header>div1</header></div>
<div class="column" draggable="true"><header>div2</header></div>
<div class="column" draggable="true"><header>div3</header></div>
<div class="column" draggable="true"><header>div4</header></div>
<div class="column" draggable="true"><header>div5</header></div>
<div class="column" draggable="true"><header>div6</header></div>
</div>
</body>
<script>
var columns = document.querySelectorAll('#columns .column');
var dragEl = null;
[].forEach.call(columns,function(column){
column.addEventListener("dragstart",domdrugstart,false);
column.addEventListener('dragenter', domdrugenter, false);
column.addEventListener('dragover', domdrugover, false);
column.addEventListener('dragleave', domdrugleave, false);
column.addEventListener('drop', domdrop, false);
column.addEventListener('dragend', domdrapend, false);
});
function domdrugstart(e) {
e.target.style.opacity = '0.5';
dragEl = this;
e.dataTransfer.effectAllowed = "move";
e.dataTransfer.setData("text/html",this.innerHTML);
}
function domdrugenter(e) {
e.target.classList.add('over');
}
function domdrugover(e) {
if (e.preventDefault) {
e.preventDefault();
}
e.dataTransfer.dropEffect = 'move';
return false;
}
function domdrugleave(e) {
e.target.classList.remove('over');
}
function domdrop(e) {
if (e.stopPropagation) {
e.stopPropagation();
}
if (dragEl != this) {
dragEl.innerHTML = this.innerHTML;
this.innerHTML = e.dataTransfer.getData('text/html');
}
return false;
}
function domdrapend(e) {
[].forEach.call(columns, function (column) {
column.classList.remove('over');
column.style.opacity = '1';
});
}
</script>
</html>
拖拽排序
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 将 MeiqiaSDK-Android[https://github.com/Meiqia/MeiqiaSDK-A...
- 从文章标题就能看出是一个专门做图片上传的插件,拖拽排序借鉴了网上的一个方法,融合到了本插件中,提供了一个专门捕捉图...