• html 绘制矩形轨迹,选中区域


    图片

     code

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
    .box {
        border:1px solid black;
         0px;
        height: 0px;
        position: absolute;
         
        z-index:-1;
    }
    div{
    opacity:1;
    border:1px solid black;
    800px;
    height:500px;
     
    }
    </style>
    <script type="text/javascript">
    window.onload = function(e) {
        e = e || window.event;
        // startX, startY 为鼠标点击时初始坐标
        var startX, startY; 
        // 鼠标按下
        document.onmousedown = function(e) {
            startX = e.pageX;
            startY = e.pageY;
            // 在页面创建 box
            var active_box = document.createElement("div");
            active_box.id = "active_box";
            active_box.className = "box";
            active_box.style.top = startY + 'px';
            active_box.style.left = startX + 'px';
            document.body.appendChild(active_box);
            active_box = null;
        };   
        // 鼠标移动
        document.onmousemove = function(e) {
            // 更新 box 尺寸
            if(document.getElementById("active_box") !== null) {
                var ab = document.getElementById("active_box");
                if(e.pageX>startX){
                    if(e.pageY>startY){
                        active_box.style.top = startY + 'px';
                        active_box.style.left = startX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }else if(e.pageY==startY){
                        active_box.style.top = startY + 'px';
                        active_box.style.left = startX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }else{
                        active_box.style.top = e.pageY + 'px';
                        active_box.style.left = startX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }
                }else if(e.pageX==startX){
                    if(e.pageY>startY){
                        active_box.style.top = startY + 'px';
                        active_box.style.left = startX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }else if(e.pageY==startY){
                        active_box.style.top = startY + 'px';
                        active_box.style.left = startX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }else{
                        active_box.style.top = e.pageY + 'px';
                        active_box.style.left = startX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }
                }else{
                    if(e.pageY>startY){
                        active_box.style.top = startY + 'px';
                        active_box.style.left = e.pageX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }else if(e.pageY==startY){
                        active_box.style.top = e.pageY + 'px';
                        active_box.style.left = e.pageX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }else{
                        active_box.style.top = e.pageY + 'px';
                        active_box.style.left = e.pageX + 'px';
                        ab.style.width = Math.abs(e.pageX - startX) + 'px';
                        ab.style.height = Math.abs(e.pageY - startY) + 'px';
                    }  
                }
                 
            }
        };    
        // 鼠标抬起
        document.onmouseup = function(e) {
            if(document.getElementById("active_box") !== null) {
                var ab = document.getElementById("active_box");
                ab.removeAttribute("id");
                // 如果长宽均小于 3px,移除 box
                document.body.removeChild(ab);
            }
        };
    };
    </script>
    </head>
    <body>
    <div></div>
    <p>点击鼠标左键并拖动绘制矩形</p>
    </body>
    </html>
  • 相关阅读:
    YOLO V5
    YOLO系列(单阶段目标检测)
    优化算法
    算法总结
    图像分类算法
    ResNet网络(里程碑)
    GoogleNet网络(纵横交错)
    VGGNet网络(走向深度)
    AlexNet网络(开山之作)
    案例
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9657343.html
Copyright © 2020-2023  润新知