• 拖拽案例


    1.拖拽案例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            * {
                margin: 0;
                padding: 0;
            }
    
            .nav {
                height: 30px;
                background: #036663;
                border-bottom: 1px solid #369;
                line-height: 30px;
                padding-left: 30px;
            }
    
            .nav a {
                color: #fff;
                text-align: center;
                font-size: 14px;
                text-decoration: none;
    
            }
    
            .d-box {
                width: 400px;
                height: 300px;
                border: 5px solid #eee;
                box-shadow: 2px 2px 2px 2px #666;
                position: absolute;
                top: 40%;
                left: 40%;
                background-color: white;
    
                /* 不让文字被选中 */
                -webkit-user-select:none;
                -moz-user-select:none;
                -ms-user-select:none;
                user-select:none;
            }
    
            .hd {
                width: 100%;
                height: 25px;
                background-color: #7c9299;
                border-bottom: 1px solid #369;
                line-height: 25px;
                color: white;
                cursor: move;
            }
    
            #box_close {
                float: right;
                cursor: pointer;
            }
           </style>
    </head>
    <body>
        <div class="nav">
        <a href="javascript:;" id="register">注册信息</a>
    </div>
    <div class="d-box" id="d_box">
        <div class="hd" id="drop">注册信息 (可以拖拽)
            <span id="box_close">【关闭】</span>
        </div>
        <div class="bd"></div>
        <!-- <script src="common.jd"></script> -->
        <script>
            var box = document.getElementById('d_box');
            var drop = document.getElementById('drop');
            drop.onmousedown = function (e) {
                var x = e.pageX - box.offsetLeft;
                var y = e.pageY - box.offsetTop;
                // 鼠标在文档中移动
                document.onmousemove = function (e) {
                    // 盒子的坐标
                    var boxX = e.pageX - x;
                    var boxY = e.pageY - y;
                    box.style.left = boxX + 'px';
                    box.style.top = boxY + 'px';
                }
            }
            document.onmouseup = function () {
                document.onmousemove = null;
            }
    
            // 点击关闭按钮, 隐藏盒子
            var box_close = document.getElementById('box_close');
            box_close.onclick = function () {
                box.style.display = 'none';
            }
        </script>
    </div>
    </body>
    </html>
  • 相关阅读:
    gitbook 入门
    mac 手动卸载软件位置
    idea 版本控制忽略文件、文件夹设置
    Mac .DS_Store 隐藏文件和清理.DS_Store的方法
    mac 打开整个系统的隐藏文件
    js拼接字符串,字符串转数组
    新一代 javascript 模板引擎:artTemplate-3.0
    webpack+express多页站点开发
    Vue2学习笔记:组件(Component)
    Vue2学习笔记:过渡效果css
  • 原文地址:https://www.cnblogs.com/guniang/p/12021157.html
Copyright © 2020-2023  润新知