jq弹窗拖动改变宽高

预览效果

javascript 复制代码
<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>
javascript 复制代码
.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注释

javascript 复制代码
$(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;
    });
});
相关推荐
夏花里的尘埃17 分钟前
vue3实现echarts——小demo
前端·vue.js·echarts
努力学习的木子1 小时前
uniapp如何隐藏默认的页面头部导航栏,uniapp开发小程序如何隐藏默认的页面头部导航栏
前端·小程序·uni-app
java小郭4 小时前
html的浮动作用详解
前端·html
水星记_4 小时前
echarts-wordcloud:打造个性化词云库
前端·vue
强迫老板HelloWord5 小时前
前端JS特效第22波:jQuery滑动手风琴内容切换特效
前端·javascript·jquery
续亮~6 小时前
9、程序化创意
前端·javascript·人工智能
RainbowFish6 小时前
「Vue学习之路」—— vue的常用指令
前端·vue.js
Wang's Blog6 小时前
Webpack: 三种Chunk产物的打包逻辑
前端·webpack·node.js
pan_junbiao7 小时前
HTML5使用<blockquote>标签:段落缩进
前端·html·html5
38kcok9w2vHanx_7 小时前
从0开始搭建vue项目
前端·javascript·vue.js