zoukankan      html  css  js  c++  java
  • <转>拖拽DIV最少代码

     
    <html>
    <title></title>
      <script type="text/javascript">
            function Drag(obj)
            {
                var obj = document.getElementById(obj);
                obj.style.position = "absolute";
                obj.onmousedown = function(e)
                {
                    e = e || window.event;
                    var x = e.offsetX;
                    var y = e.offsetY;
                    document.onmousemove = function(e)
                    {
                        e = e || window.event;
                        obj.style.left = (e.clientX - x) + "px";
                        obj.style.top = (e.clientY - y) + "px";
                    }
                    document.onmouseup = function()
                    {
                        document.onmousemove = null;
                        obj.onmousedown = null;
                    }
                }
            }
        </script>
    </head>
    <body>
        <div id="div"  style="background-color:White;300px;height:250px;">
         <div id="p" style="cursor:move;background-color:Red;300px;height:25px;" onmousedown="Drag('div')">        
         </div>
         <div>
         正文  
         </div>
        </div>
    </body>
    </html>
  • 相关阅读:
    Google Protocol Buffers学习
    C学习笔记-一些知识
    前端相关
    Spark笔记-gz压缩存储到HDFS【转】
    maven笔记-将本地jar包打包进可执行jar中
    Spark运行时错误与解决
    机器学习笔记
    Spark笔记-DataSet,DataFrame
    云平台各层解释
    linux笔记-多服务器同时执行相同命令
  • 原文地址:https://www.cnblogs.com/sunny0515/p/2757143.html
Copyright © 2011-2022 走看看