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>
  • 相关阅读:
    全程软件测试_项目启动
    全程软件测试_规范测试过程
    python_json常用的方法
    python_eval的用法
    python_判断字符串编码的方法
    python_Notepad++编码集的说明
    python_编码集的介绍
    初识HTML
    mysql学习目录
    python学习目录
  • 原文地址:https://www.cnblogs.com/sunny0515/p/2757143.html
Copyright © 2011-2022 走看看