Skip to content

Commit

Permalink
update drag-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-xin committed Apr 29, 2017
1 parent a57a8a9 commit 82fe857
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
20 changes: 17 additions & 3 deletions drag-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@
margin: 0;
padding: 0;
}
.main{
html,body{
height: 100%;
}
#app{
position: relative;
width: 100%;
max-width: 1150px;
height: 100%;
max-width: 980px;
margin: auto;
}
.list{
padding:10px;
height: 20px;
border-bottom: 1px solid #ddd;
}
#recycle{
position: absolute;
bottom: 0;
width: 100%;
height: 70px;
line-height: 70px;
text-align: center;
background: #ddd;
}
</style>
</head>
<body>
Expand All @@ -33,7 +47,7 @@
<div class="list" draggable="true">这里是列表6的标题</div>
<div class="list" draggable="true">这里是列表7的标题</div>
</div>
<div id="test"></div>
<div id="recycle">回收站</div>
</div>
<script src="index.js"></script>
<script src="http://timruffles.github.io/ios-html5-drag-drop-shim/ios-drag-drop.js"></script>
Expand Down
5 changes: 5 additions & 0 deletions drag-demo/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var iosDragDropShim = { enableEnterLeave: true } // 兼容移动端
var source = document.querySelectorAll('.list'),
recycle = document.getElementById('recycle'),
dragElement = null, // 用于存放拖动元素
lock = true; // 最后元素拖放拖放时会进入enter和leave的循环,用来锁住

Expand Down Expand Up @@ -33,5 +34,9 @@ for(var i = 0; i < source.length; i++){
}, false)
};

recycle.addEventListener('drop', function(ev){ // 拖进回收站则删除该元素
dragElement.parentNode.removeChild(dragElement);
}, false)

document.ondragover = function(e){e.preventDefault();} // 必须设置dragover阻止默认事件
document.ondrop = function(e){e.preventDefault();}

0 comments on commit 82fe857

Please sign in to comment.