zoukankan      html  css  js  c++  java
  • 使用Html5和Js进行拖动

     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=" 200px;border: 1px solid gray">请拖放</div>

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

    </body>

  • 相关阅读:
    PhpStorm函数注释的设置
    thinkphp5 返回数组提示variable type error: array
    js获取json对象中的key和value,并组成新数组
    PHP生成随机字符串与唯一字符串
    yii2-admin扩展自定义目录
    PHP7.3发布啦
    服务器环境从PHP5升级到PHP7
    亲测能用的mysqli类,挺好用的
    PHP必用代码片段
    git flow的使用
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6889896.html
Copyright © 2011-2022 走看看