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

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style>
    #box {
         100px;
        height:100px;
        background: red;
        position: absolute;
        left: 0;
        top: 0;
    }

    .new{
         100px;
        height: 100px;
        position: absolute;
        border: green 1px dashed;
    }
    </style>
    <script>
    window.onload = function(){
        var oBox = document.getElementById('box');
        oBox.onmousedown = function(ev){
            var oEvent = ev || event;
            var disX = oEvent.clientX - oBox.offsetLeft;
            var disY = oEvent.clientY - oBox.offsetTop;
            var oNew = document.createElement('div');
            oNew.style.left = oBox.offsetLeft + 'px';
            oNew.style.top = oBox.offsetTop + 'px';
            oNew.className = 'new';
            oBox.parentNode.appendChild(oNew);
            
            document.onmousemove= function(ev){
                var oEvent = ev || event;    
                var l = oEvent.clientX - disX;
                var t = oEvent.clientY - disY;
                oNew.style.left = l + 'px';
                oNew.style.top = t + 'px';
            }    
            document.onmouseup = function(){
                document.onmousemove = null;
                document.onmouseup = null;
                oBox.style.left = oNew.offsetLeft + 'px';
                oBox.style.top = oNew.offsetTop + 'px';
                oBox.parentNode.removeChild(oNew);
                oBox.releaseCapture && oBox.releaseCapture();     
            }
            oBox.setCapture && oBox.setCapture();
            return false;
        }
    }
    </script>
    </head>

    <body>
    <div id="box"></div>
    </body>
    </html>

  • 相关阅读:
    【Coreforces 1253E】
    计数专题乱做
    PKUWC2020乱做
    多项式板子
    notepad
    2021.4.9
    2021.4.8
    2021.3.31
    2021.3.26
    2021.3.25
  • 原文地址:https://www.cnblogs.com/guolimin/p/6091302.html
Copyright © 2011-2022 走看看