zoukankan      html  css  js  c++  java
  • 拖拽——带框

    <!DOCTYPE html>

    <html>

     

    <head>

    <meta charset="UTF-8">

    <title></title>

    <style type="text/css">

    #box {

    height: 300px;

    width: 300px;

    background-color: green;

    position: absolute;

    left: 0;

    top: 0;

    }

     

    .border {

    border: 2px dashed red;

    position: absolute;

    }

    </style>

    </head>

     

    <body>

    <div id="box">

     

    </div>

    </body>

    <script type="text/javascript">

    var box = document.getElementById("box");

    var x = 0;

    var y = 0;

    box.onmousedown = function(ev) {

    var oEvent = ev || event;

    x = oEvent.clientX - box.offsetLeft;

    y = oEvent.clientY - box.offsetTop;

    //产生一个新的div,即为拖拽的框

    var div = document.createElement("div");

    div.className = "border";

    div.style.width = box.offsetWidth + "px";

    div.style.height = box.offsetHeight + "px";

    div.style.left = box.offsetLeft + "px";

    div.style.top = box.offsetTop + "px";

    document.body.appendChild(div)

    //鼠标移动的函数

    document.onmousemove = function(ev) {

    var oEvent = ev || event;

     

    var L = oEvent.clientX - x;

    var T = oEvent.clientY - y;

     

    div.style.left = L + "px";

    div.style.top = T + "px";

    }

    //鼠标抬起的函数

    document.onmouseup = function() {

    this.onmousemove = null;

    this.onmouseup = null;

    box.style.left = div.offsetLeft + "px";

    box.style.top = div.offsetTop + "px";

    document.body.removeChild(div);

    }

     

    return false;

     

    }

    </script>

     

    </html>

  • 相关阅读:
    [CFNews] EnCase v7更新至7.05.1
    [CFNews] Guidance 发布EnCase v7.05和EnCase Portable v4.1
    [CFNews] 首届国际电子数据取证调查会议将于9月21日在北京召开
    [转载] iPhone 5 forensics – prepare to be assimilate
    [CFNews] Oxygen Forensic Suite发布4.6
    [Ext]在按钮栏添加Checkbox
    [转]动态改变图片的useMap属性导致IE假死或崩溃!
    [转]Custom Configuration Section Handler in .NET 2.0
    判断当前的网络状态(C#)
    自定义配置节示例(.NET 2.0)
  • 原文地址:https://www.cnblogs.com/niuniudashijie/p/6129787.html
Copyright © 2011-2022 走看看