zoukankan      html  css  js  c++  java
  • 元素盒子左右拖曳(左边拖动多少右边减少多少宽度)

    <!doctype html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <title>元素拖动改变大小</title>
    </head>

    <body>
        <input class="control" value="" style="float:left;padding: 2px; padding-bottom: 0px; 25%;" placeholder="显示的文本信息" />
        <label onmousedown="mousedown(this,event)" style="float:left;cursor:e-resize;max-2px;2px;background:blue">&nbsp;</label>
        <div style="border: 1px dashed pink;  70%;height: 200px;display: inline-block;"></div>
        <script src="./jquery-1.7.1.min.js"></script>
        <script>

            var isResizing = false,
                lastDownX = 0;
            var docu = null;
            function mousedown(doc, e) {
                docu = doc;
                isResizing = true;
                lastDownX = e.clientX;
            }

            let W = $('.control').width();
            let Rw = $('div').width();
            $(document).on('mousemove', function (e) { 
                if (!isResizing) return;
                var container = $(docu).prev(".control");
                var offsetRight = (e.clientX - container.offset().left - container.width());
                container.css("width", (container.width() + offsetRight-10) + "px");
                $('div').css("width", (Rw-(container.width() + offsetRight-10)+W) + "px");
            }).on('mouseup', function (e) { 
                isResizing = false;
            });

        </script>
    </body>

    </html>
  • 相关阅读:
    使用RationalRose画活动图
    使用RationalRose画用例图
    UML工具RationalRose下载和安装
    使用BootStrap布局网站首页
    BootStrap入门
    使用JQuery发送请求局部刷新页面
    使用JQuery完成表单的校验(扩展)
    Window 由于未经处理的异常,进程终止。
    MySQL数据类型DECIMAL用法
    推荐收藏 —— MySQL视图详细介绍
  • 原文地址:https://www.cnblogs.com/duhui/p/14177316.html
Copyright © 2011-2022 走看看