JavaScript Drag-n-Drop & Refrence-Line (T.B.D)

Drap Object by Container border checking

<head>
    <base href="">
    <meta charset="utf-8">
    <meta name="author" content="unix2linux">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="A powerful and conceptual apps base dashboard template that especially build for developers and programmers.">
    <!-- Fav Icon  -->
    <link rel="shortcut icon" href="./images/favicon.png">
    <!-- Page Title  -->
    <title>Designer</title>
    <!-- StyleSheets  -->
    <link rel="stylesheet" href="./assets/css/dashlite.css?ver=2.2.0">
    <link id="skin-default" rel="stylesheet" href="./assets/css/theme.css?ver=2.2.0">
    <style>
        .outer-container {
            width: 800px;
            height: 600px;
            border: 1px dashed red;
            margin: auto;
            position: relative;
        }
         .inner-object {
            width: 160px;
            height: 120px;
            background-color:forestgreen;
            cursor: move;
            position: absolute;
            top: 20px;
        }
        .inner-object:hover {
            box-shadow: 1px 1px 5px 0px rgba(0, 0, 0, 0.618);
            -webkit-box-shadow: 1px 1px 5px 0px rgba(0, 0, 0, 0.618);
            -moz-box-shadow: 1px 1px 5px 0px rgba(0, 0, 0, 0.618);
        }
    </style>
</head>
<body>
	<div class="outer-container">
    	<div class="inner-object" style="left: 40px;"></div>
    	<div class="inner-object" style="right: 40px;background-color: blue"></div>
  	</div>
    <script src="./assets/js/bundle.js?ver=2.2.0"></script>
    <script src="./assets/js/scripts.js?ver=2.2.0"></script>
</body>
<script>
    function dragCheckBorder(dragObj, containerObj) {
        $(dragObj).mousedown(function (e) {
            var _this = $(this)
            var containerHeight = $(containerObj)[0].offsetHeight
                containerWidth  = $(containerObj)[0].offsetWidth
            var dragHeight = $(this)[0].offsetHeight
                dragWidth  = $(this)[0].offsetWidth
            var dragX = e.clientX - $(this)[0].offsetLeft
                dragY = e.clientY - $(this)[0].offsetTop

            $(this).css('z-index','999').siblings().css('z-index','1')

            $(document).mousemove(function (e) {
                var l = e.clientX - dragX
                var t = e.clientY - dragY
                if (l < 0) {
	                l = 0
                } else if (l > containerWidth - dragWidth) {
	                l = containerWidth - dragWidth
	                }
                if (t < 0) {
	                t = 0
                } else if (t > containerHeight - dragHeight) {
	                t = containerHeight - dragHeight
                }
                _this.css({
	                left: l + 'px',
	                top: t + 'px',
                })
            })
        });
        $(document).mouseup(function () {
            $(this).off('mousemove')
        });
    }
</script>
<script>
    dragCheckBorder('.inner-object', '.outer-container');
</script>
https://github.com/givanz/VvvebJs

https://github.com/kevinchappell/formBuilder

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值