• 可拖拽可扩展面板


    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="utf-8">
            <title></title>
            <style>
                * {
                    margin: 0;
                    padding: 0;
                }
                .panel {
                     400px;
                    height: 200px;
                    background-color: azure;
                    position: absolute;
                    left: 100px;
                    top: 100px;
                }
                .title {
                     100%;
                    height: 20px;
                    line-height: 20px;
                    text-align: center;
                    color: white;
                    font-size: small;
                    background-color: darkgrey;
                    cursor: pointer;
                }
                .dr {
                    position: absolute;
                     30px;
                    height: 100%;
                    right: -15px;
                    top: 0;
                    /*background-color: red;*/
                    
                    cursor: e-resize;
                }
                .db {
                    position: absolute;
                    height: 30px;
                     100%;
                    bottom: -15px;
                    /*    background-color: blue;*/
                    
                    cursor: n-resize;
                }
            </style>
        </head>
    
        <body>
            <div class="panel">
                <div class="title">可扩展panel</div>
            </div>
    
            <div class="panel">
                <div class="title">可扩展panel</div>
            </div>
        </body>
    
    </html>
    <script>
        function drag(obj, opanel) {
            var disx = 0;
            var disy = 0;
            resizable(opanel);
            obj.onmousedown = function(e) {
                var e = e || event;
                disx = e.clientX - opanel.offsetLeft;
                disy = e.clientY - opanel.offsetTop;
                document.onmousemove = function(e) {
                    var e = e || event;
                    opanel.style.left = (e.clientX - disx) + "px";
                    opanel.style.top = (e.clientY - disy) + "px";
                }
                document.onmouseup = function() {
                    document.onmousemove = null;
                    document.onmouseup = null;
                }
                return false;
            }
        }
    
        function resizable(objpanel) {
            var db = document.createElement("div");
            db.className = "db";
            var dr = document.createElement("div");
            dr.className = "dr";
            var drb = document.createElement("div");
            drb.className = "drb";
            objpanel.appendChild(db);
            objpanel.appendChild(dr);
            objpanel.appendChild(drb);
            resize(db, objpanel, "db");
            resize(dr, objpanel, "dr");
            resize(drb, objpanel, "drb");
        }
    
        function resize(objdiv, objpanel, type) {
            var disx = 0;
            var disy = 0;
            objdiv.onmousedown = function(e) {
                var e = e || event;
                disx = e.clientX - objdiv.offsetLeft;
                disy = e.clientY - objdiv.offsetTop;
                document.onmousemove = function(e) {
                    var e = e || event;
                    objdiv.style.left = e.clientX - disx;
                    objdiv.style.top = e.clientY - disy;
                    switch (type) {
                        case "drb":
                            objpanel.style.width = e.clientX - disx+15 + "px";
                            objpanel.style.height = e.clientY - disy+15 + "px";
                            break;
                        case "dr":
                            objpanel.style.width = e.clientX - disx +15+ "px";
                            break;
                        case "db":
                            document.title = e.clientY - disy;
                            objpanel.style.height = e.clientY - disy +15+ "px";
                            break;
                    }
                }
                document.onmouseup = function() {
                    document.onmousemove = null;
                    document.onmouseup = null;
                }
                return false;
            }
        }
        window.onload = function() {
            drag(document.getElementsByClassName("title")[0], document.getElementsByClassName("panel")[0]);
            drag(document.getElementsByClassName("title")[1], document.getElementsByClassName("panel")[1]);
        }
    </script>
  • 相关阅读:
    从‘void*’到‘int’的转换损失精度
    ../lib//libscsdblog.so: undefined reference to `pthread_atfork'
    使用Crypto++库的CBC模式实现加密
    VIM常用命令
    mysql bin-log三种模式
    windows64位Oracle安装和PL/SQL配置
    Maven项目中突然找不到Build Path或maven dependencies library
    org.springframework.beans.factory.config.MethodInvokingFactoryBean的使用
    使用Spring的StingUtils的commaDelimitedListToStringArray来获取字符串数组
    Spring注入
  • 原文地址:https://www.cnblogs.com/fierceeagle/p/4530614.html
Copyright © 2020-2023  润新知