1.启动拖动:将元素draggable属性值设为true
2.为被拖动元素的ondragstart事件指定监听器,在该操作中让拖动操作可携带数据
3.在放的效果中,为document的ondragover事件指定监听器, 在监听器中取消document对拖动事件的默认行为
4.不同浏览器对拖放操作的默认动作并不相同,如果开发者希望取消拖放操作的默认动作
可为document的ondrop事件绑定监听器,取消事件的默认行为
var source = document.getElementByIdx_x_x_x('source'); source.ondragstart = function(evt){ //让拖动操作携带数据 evt.dataTransfer.setData('text','www.fkjave.org'); } document.ondragover = function(evt){ //取消事件的默认行为 return false; }
document.ondrop = function(evt){ source.style.position = 'absolute'; source.style.left = evt.pageX + 'px'; source.style.top = evt.pageY + 'px'; /
var source = document.getElementByIdx_x_x_x('source'); source.ondragstart = function(evt){ //让拖动操作携带数据 evt.dataTransfer.setData('text','www.fkjave.org'); } document.ondragover = function(evt){ //取消事件的默认行为 return false; }
document.ondrop = function(evt){ source.style.position = 'absolute'; source.style.left = evt.pageX + 'px'; source.style.top = evt.pageY + 'px'; /
