jq弹窗拖动改变宽高

预览效果

在这里插入图片描述

<div class='tishiMask'>
	<div class="tishiEm">
		<div id="coor"></div>
		<div class="topNew ismove">
			<span class="ismove">提示</span>
			<p onclick="closeTishi()">×</p>
		</div>
		<div class="bottomNew">
			<p>提示文字软件</p>
			<div class="newDesignBtn">
				<input type="button" value="确定" class="btnLeft" onclick="closeTishi()" >
				<input type="button" value="取消" onclick="closeTishi(this)" class="btnRight">
			</div>
		</div>
	</div>
</div>
.tishiMask{
	width: 100%;
	height: 100%;
	position: fixed;
	top: 0;
	left: 0;
	background-color: rgba(0, 0, 0, .18);
	display: block;
	z-index: 99999;
}
.tishiEm {
	z-index: 99999;
	/* display: none; */
	/* -webkit-transition: -webkit-box-shadow .2s; */
	/* transition: box-shadow .2s; */
	position: fixed;
	height: 220px;
	width: 300px;
	top: 38%;
	/* margin-top: -100px; */
	left: 43%;
	/* margin-left: -150px; */
	background: #fff;
	border-radius: 5px 5px 0px 0px;
	-webkit-box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.4);
	box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.4);
	/* -webkit-transition: -webkit-box-shadow .2s; */
	/* transition: box-shadow .2s; */
	/* transition: all .4s; */
	/* -webkit-transition: all .4s; */
	/* -moz-transition: all .4s; */
}

.tishiEm .topNew {
	overflow: hidden;
	background-image: linear-gradient(183deg, #3d95ea 0%, #70b0e6 100%);
	border-radius: 5px 5px 0px 0px;
}

.tishiEm .topNew span {
	color: #fff;
	font-size: 12px;
	height: 34px;
	line-height: 34px;
	display: block;
	float: left;
	margin-left: 10px;
}

.tishiEm .topNew p {
	float: right;
	color: #fff;
	font-size: 20px;
	height: 34px;
	line-height: 34px;
	display: block;
	margin-right: 10px;
	cursor: pointer;
}

.tishiEm .bottomNew {
	margin: 0px 0px;
}

.tishiEm .bottomNew {
	text-align: center;
}

.tishiEm .bottomNew p {
	font-size: 12px;
	height: 20px;
	line-height: 20px;
}
.tishiEm .bottomNew .newDesignBtn {
	overflow: hidden;
	width: 100%;
	height: auto;
	display: flex;
	justify-content: flex-end;
	align-items: center;
	position: absolute;
	bottom: 10px;
	left: 0;
}

.tishiEm .bottomNew .newDesignBtn .btnLeft {
	display: block;
	float: left;
	box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.22);
	background: #5da2e5;
	color: #fff;
	font-size: 12px;
	width: auto;
	text-align: center;
	height: 24px;
	line-height: 24px;
	border-radius: 4px;
	border: none;
	cursor: pointer;
	padding: 0px 14px;
	border: 1px solid #5da2e5;
}

.tishiEm .bottomNew .newDesignBtn .btnLeft:hover {
	background: #1a78d9;
	border: 1px solid #0069b8;
	color: #fff;
}

.tishiEm .bottomNew .newDesignBtn .btnRight {
	display: block;
	float: left;
	box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.22);
	background: #dcdcdc;
	color: #383838;
	font-size: 12px;
	width: auto;
	text-align: center;
	height: 24px;
	line-height: 24px;
	border-radius: 4px;
	margin-right: 28px;
	margin-left: 10px;
	border: none;
	cursor: pointer;
	padding: 0px 14px;
	border: 1px solid #dcdcdc;
}

.tishiEm .bottomNew .newDesignBtn .btnRight:hover {
	background: #c4c4c4;
	color: #383838;
	border: 1px solid #aaa;
}
#coor, #coor_set, #coor_syt {
	width: 20px;
	height: 20px;
	overflow: hidden;
	cursor: se-resize;
	position: absolute;
	right: 0;
	bottom: 0;
	/* background-color: #09c; */
	background: url(./../images/scale.png);
	background-size: 100% 100%;
	transform: rotate(270deg);
	z-index: 999;
}

类名tishiEm设置宽高为缩小最小宽高。

注意下方js注释

$(function () {
    $(document).mousemove(function (e) {

        if (!!this.move_gy) {

            var posix_gy = !document.move_target_gy ? { 'x': 0, 'y': 0 } : document.move_target_gy.posix_gy,
                callback_gy = document.call_down_gy || function () {
                    let viewWidth = $(document).width();
                    let maxLeft = viewWidth - $(".tishiEm").width();   // 左侧最大移动量

                    let viewHeight = $(document).height();
                    let maxHeight = viewHeight - $(".tishiEm").height();   // 底部最大移动量

                    let currentTop = e.pageY - posix_gy.y;
                    let currentLeft = e.pageX - posix_gy.x;

                    if (currentTop <= 0 || currentLeft <= 0 || currentLeft >= maxLeft || currentTop >= maxHeight) {
                        return
                    } else {
                        $(this.move_target_gy).offset({
                            'top': currentTop,
                            'left': currentLeft
                        });
                    }
                };

            callback_gy.call(this, e, posix_gy);
        }


    }).mouseup(function (e) {
        if (!!this.move_gy) {
            var callback_gy = document.call_up_gy || function () {
            };
            callback_gy.call(this, e);
            $.extend(this, {
                'move_gy': false,
                'move_target_gy': null,
                'call_down_gy': false,
                'call_up_gy': false
            });
        }
    });
    var $box = $('.tishiEm').mousedown(function (e) {
        let offset = $(this).offset();


        this.posix_gy = { 'x': e.pageX - offset.left, 'y': e.pageY - offset.top };
        if (!$(e.target).hasClass('ismove')) {      // 只允许蓝色区域可拖动
            return;
        } else {
            $.extend(document, { 'move_gy': true, 'move_target_gy': this });
        }


    }).on('mousedown', '#coor', function (e) {
        var posix_gy = {
            'w': $box.width(),
            'h': $box.height(),
            'x': e.pageX,
            'y': e.pageY
        };

        $.extend(document, {
            'move_gy': true, 'call_down_gy': function (e) {
            	//下方为最小宽高  同步上方css
                $box.css({
                    'width': Math.max(300, e.pageX - posix_gy.x + posix_gy.w),
                    'height': Math.max(220, e.pageY - posix_gy.y + posix_gy.h)
                });
            }
        });
        return false;
    });
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你爱我吗。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值