码迷,mamicode.com
首页 > Web开发 > 详细

使用Html5和Js进行拖动

时间:2015-07-24 10:45:37      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:html5   javascript   

 function init() {
            var source = document.getElementById("dragme");
            var dest = document.getElementById("text");
        
            source.addEventListener("dragstart", function(ev) {
   <script type="text/javascript">
                var dt = ev.dataTransfer;
                dt.effectAllowed = ‘all‘;
             
                dt.setData("text/plain", "拖动");
            }, false);
     
            dest.addEventListener("dragend", function(ev) {
          
                ev.preventDefault();
              
            }, false);
          
            dest.addEventListener("drop", function (ev) {
               
                var dt = ev.dataTransfer;
                var text = dt.getData("text/plain");
                dest.textContent += text;
               
                ev.preventDefault();
                ev.stopPropagation();
            }, false);
        }

        document.ondragover = function(e) { e.preventDefault(); };
                    document.ondrop = function(e) { e.preventDefault(); };

              
        

    </script>

<body onload="init()">

        <div id="dragme" draggable="true" style="width: 200px;border: 1px solid gray">请拖放</div>

        <div id="text" style="width: 200px; height: 200px;border: 1px solid gray"></div>

</body>

版权声明:本文为博主原创文章,未经博主允许不得转载。

使用Html5和Js进行拖动

标签:html5   javascript   

原文地址:http://blog.csdn.net/u011936353/article/details/47036341

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!