var box = boxs[i];
box.onselectstart = function() {
return false;
};
box.ondragstart = function(e) {
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/plain', e.target.outerHTML);
e.dataTransfer.setDragImage(e.target, 0, 0);
drag = this;
return true;
};
box.ondragend = function(e) {
drag = null;
return false
};
}
for (var i = 0; i < bins.length; i++) {
var bin = bins[i];
//当拖曳元素进入目标元素
bin.ondragover = function(e) {
e.preentDefault();
return true;
};
//拖拽元素在目标元素上移动
bin.ondragenter = function(e) {
this.style.backgroundColor = '#eeeeff';
return true;
};
//拖拽元素在目标元素上离开
bin.ondragleave = function(e) {
this.style.backgroundColor = '#fff';
return true;
};
//拖拽的元素在目标元素上同时鼠标放开
bin.ondrop = function(e) {
if (drag) {
drag.parentNode.removeChild(drag);
this.appendChild(drag);
}
this.style.backgroundColor = '#fff';
return false;
};
}
document.body.ondrop = function(e) {
e.preventDefault();
e.stopPropagation();
}
</script>
</body>
</html>
以上就是HTML5中的拖放相关资料介绍,需要的朋友可以参考一下。









