可伸缩区域

2 篇文章 0 订阅

可拖拽条

实现效果

在这里插入图片描述

实现代码

<style lang="scss" scope>
.aside {
	width: 18%;
	min-width: 260px;
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
	flex-grow: 0;
	position: relative;
	background-color: #fff;
	height: 100%;
	padding: 0;
}
.spliter {
	position: absolute;
	right: -6px;
	top: 0;
	height: 100%;
	cursor: col-resize;
	transition: all ease .2s;
	background-color: #f6f6f6;
	&:before {
		width: 6px;
		height: 9px;
		background-image: url('../drag-tips.svg');
		background-size: contain;
		background-repeat: no-repeat;
		content: '';
		position: absolute;
		top: 50%;
		margin-top: -5px;
	}
	&:hover {
		background-color: #eee;
	}
}
.content-wrap {
	flex: 1;
	padding-left: 6px;
}
<style>
<template>
	<div ref="aside" class="aside">可伸缩内容区</div>
	<div
		class="spliter"
		@dblclick="onDoubleBlindSlide"
		@mousedown="onBindSlide"
	/>
	<div ref="content-wrap" class="content-wrap">右侧内容区</div>
</template>
<script>
export default {
	methods: {
		onDoubleBlindSlide (e){
			const asideDOM = this.$refs['aside']
			cosnt width = '18%'
			asideDOM.style.flexBasis = width
		},
		onBindSlide (e) {
			cosnt pageX = e.clientX
			const contentDOM = this.$refs['content-wrap']
			contentDOM.style.userSelect = 'none'
			const asideDOM = this.$refs['aside']
			const width = asideDOM.offsetWidth
			document.onmousemove = mouseMoveEvent => {
				const result = width + (mouseMoveEvent .clientX - pageX)
				if (result < 100 || result > 1000) return
				asideDOM.style.flexBasis = `${result}px`
			}
			document.onmouseup = () => {
				contentDOM.style.userSelect = 'inherit'
				document.onmousemove = null
				document.onmouseup = null
			}
		}
	}
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值