jquery单元素拖动框选对齐效果代码

代码语言:html

所属分类:选择器

代码描述:jquery单元素拖动框选对齐效果代码

代码标签: 元素 ) 拖动 框选 对齐 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
    <style>
        #toolbox {
            height: 120px;
            display: block;
        }
 
        #room {
            height: 500px;
        }
 
        .table {
            background-color: cornflowerblue;
            position: absolute;
            cursor: move;
            -moz-user-select: none;
            -ms-user-select: none;
            -webkit-user-select: none;
            user-select: none;
        }
 
        .vertical {
            width: 100px;
            height: 50px;
        }
 
        .horizontal {
            width: 50px;
            height: 100px;
        }
 
        #toolbox, #room {
            position: relative;
            border: 1px solid black;
            -moz-user-select: none;
            -ms-user-select: none;
            -webkit-user-select: none;
            user-select: none;
        }
 
        .selectrect {
            border: 1px solid black;
            position: relative;
        }
 
        #room .table.selected {
            border: 1px solid #4e4e4e;
        }
    </style>
</head>
<body>
    <div>
        <a id="btntopalign">上边对齐</a>
        <a id="btnleftalign">左边对齐</a>
        <a id="btnbottomalign">下边对齐</a>
        <a id="btnrightalign">右边对齐</a>
    </div>
    <div style="margin:20px;">
        <div id="toolbox">
 
            <div class="table horizontal" style="top:10px;left:10px;">
 
            </div>
 
            <div class="table vertical" style="top:10px;left:220px;">
 
            </div>
 
        </div>
        <div id="room">
 
 
        </div>
    </div>
    <script>
        $(function () {
            var selectedTool = {};
            $("#toolbox .table").mousedown(function (e) {//工具栏选择图形
                var $toolbox = $("#toolbox");
                var $prototool = $(this);
                var $newtable = $prototool.clone();
                $newtable.css({
                    "top": "+=" + $toolbox.position().top,
                    "left": "+=" + $toolbox.position().left
                })
                selectedTool.$tool = $newtable;
                $("body").append($newtable);
                selectedTool.pageX = $newtable.position().left;
                selectedTool.pageY = $newtable.position().top;
                selectedTool.origi.........完整代码请登录后点击上方下载按钮下载查看

网友评论0