首页 > 代码库 > 实现简单的拖动效果

实现简单的拖动效果

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        #div1, #div2
        {float:left; width:100px; height:35px; margin:10px;padding:10px;border:1px solid #aaaaaa;}
    </style>
    <script type="application/javascript">
        function drag(ev){
            ev.dataTransfer.setData("Text",ev.target.id);
        }
        function allowDrag(en){
            en.preventDefault();
        }
        function drop (en) {
            en.preventDefault();
            var data=http://www.mamicode.com/en.dataTransfer.getData(‘Text‘);"div1" ondrop="drop(event)" ondragover="allowDrag(event)">
        <img src="http://www.mamicode.com/123.jpg" width="80" height="80" draggable="true" ondragstart="drag(event)" id="drag2">
    </div>
    <div id="div2" ondrop="drop(event)" ondragover="allowDrag(event)"></div>
</body>
</html>


实现简单的拖动效果