效果;
代码如下;
html
<div class=;content-box;>
<el-input v-model=;content; ref=;input; type=;textarea; :rows=;10;></el-input> <div class=;bar; ;Mouse+down=;down($event); ref=;bar; >=</div> <div class=;res;></div> </div>
建立一个父子节点;父级元素必须是定位元素;设置样式如下
注意;offsetLeft代表距离当前元素最近的定位元素左边缘的距离。如果父辈元素中没有定位元素;那么就返回相对于body左边缘距离。如果没有设置position;元素找不到offsetLeft属性
style:
.content-box{
display: flex; position: relative;/*必须*/ .el-textarea{ min-width: 20%/*设置宽度范围*/ max-width: 80% } .res{ flex-grow: 1; border: 1px solid #dedede; } .bar{ cursor: col-resize; width: 10px; display: inline-block; line-height: 200px; vertical-align: middle; border: 1px solid #dedede; } }
核心;
setCaptrue;设置鼠标捕获(之后的事件捕获会作用在当前元素上)
releaseCaptrue释放鼠标捕获
js;
down(e){
console.log(e); const startX=e.clientX; const offsetX=e.target.offsetLeft;//元素左边到窗口左边的距离 e.target.setCaptrue;//设置鼠标捕获(之后的事件捕获会作用在当前元素上) document.onmousemove=(e)=>{ const endX=e.clientX; const width=offsetX-(startX-endX); if(width>200) this.$refs.input.$el.style.width=width;;px;; } document.onmouseup=(e)=>{ document.onmousemove=null; document.onmouseup=null; e.target.releaseCaptrue;//释放鼠标捕获 } }
关于定位元素;
- 就是元素的position属性值为;fixed;absolute;relative三其者之一;则为定位元素。
- static的元素为常规流元素。网页布局中;元素的排列方式一般三种;常规流;浮动;定位
相关文章
Vue3---Pinia-状态管理(环境搭建安装及各属性使用教程)详细使用教程
Vue3---Pinia-状态管理(环境搭建安装及各属性使用教程)详细使用教程,vue3 状态管理工具 pinia 使用,Vue3状态管理之Pinia的入门使用教程,Pinia使用详解(vue3默认状态管理),详解Vue3状态管理库Pinia的使用方法,Vue3 使用Pinia状态管理,vue3新一代状态管理器 — pinia的学习与使用,vue3使用pinia管理状态,vue3全家桶之-状态管理器pinia的使用,Vue3中Pinia的基本使用,上手Vue 新的状态管理 Pinia,一篇文章就够了,Pi...
vscode无法识别vue文件的问题,vscode无法识别vue文件的问题...
- 11-18VSCode升级后vue3的ts代码高亮失效
- 11-09vue脚手架安装教程
- 11-07VsCode-中执行Vue--V提示该系统禁止执行脚本
- 11-01手把手教你搭建Spring Boot+Vue前后端分离
- 10-20vue-table表格中使用input框动态添加数据
- 10-19vue2版本下如何分环境打包
网友评论
快盘下载暂未开通留言功能。
-
推荐文章
最新文章
文章排行