基于el-dialog, 封装了一下。,实在懒得写,所以直接把代码 粘出来了

大概粘了一下效果。自己体会把。

组件使用

 <el-dialogv-dialogDragref="xhzqDialog"class="xhzqDialog":title="title":fullscreen="isfullscreen":visible.sync="dialogVisible":append-to-body="true":close-on-click-modal="false":show-close="false":width="width":class="isminimize? 'isminimize': ''"center><div v-show="!isminimize" slot="title" class="medium"><div></div><div class="centers"><span>{{title}}</span></div><div class="icons"><i class="iconfont icon-minus" style="font-size: 24px" @click="minimize"></i><i :class="isfullscreen? 'iconfont icon-full-screen-exit' : 'iconfont icon-full-screen' " style="font-size: 24px" @click="IsFullscreen"></i><i class="iconfont icon-close" style="font-size: 24px" @click="closeDialog"></i></div></div><div v-show="isminimize" slot="title"  class="horn"><div class="lefts"><span>{{title}}</span></div><div class="centers"><i class="iconfont icon-full-screen" style="font-size: 24px" @click="minimize"></i></div><div class="rights"><i class="iconfont icon-close" style="font-size: 24px" @click="closeDialog"></i></div></div><div v-show="!isminimize" class="dialogBody"><slot></slot></div><div v-show="!isminimize" v-if="isFooter" class="dialogFooter"><slot name="footer" solt="footer"></slot></div></el-dialog>

  

数据定义

 data() {return {isfullscreen: false, // 全屏isminimize: false, // 最小化dialogVisible: false // 隐藏弹窗}},

 传递参数

    props: {width: {type: String,default: '50%'},title: {type: String,default: ''},isFooter: { // 是否显示脚部type: Boolean,default: true}},

  组件方法

 methods: {// 最小化minimize() {this.isminimize = !this.isminimizeif (this.isfullscreen) this.isfullscreen = !this.isfullscreen},// 关闭弹窗closeDialog() {this.dialogVisible = false},// 打开弹窗openDialog() {this.dialogVisible = true},// 全屏IsFullscreen() {this.isfullscreen = !this.isfullscreenif (this.isfullscreen) this.$emit('isfullscreen')}},

  自定义指令

directives: {dialogDrag: {bind(el, binding, vnode, oldVnode) {const dialogHeaderEl = el.querySelector('.el-dialog__header')const dragDom = el.querySelector('.el-dialog')dialogHeaderEl.style.cursor = 'move'// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)// const fixedX =// const fixedY =dialogHeaderEl.onmousedown = (e) => {// 判断当前是否为全屏状态const path = event.path || (event.composedPath && event.composedPath())const isFull = path.find(s => {if (s.className === undefined) {return false} else {return s.className.indexOf('is-fullscreen') > -1}})if (isFull !== undefined) {return}const isMinix = path.find(s => {if (s.className === undefined) {return false} else {return s.className.indexOf('isminimize') > -1}})if (isMinix !== undefined) {return}// 鼠标按下,计算当前元素距离可视区的距离const disX = e.clientX - dialogHeaderEl.offsetLeftconst disY = e.clientY - dialogHeaderEl.offsetTop// 获取到的值带px 正则匹配替换let styL, styT// 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为pxif (sty.left.includes('%')) {styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)} else {styL = +sty.left.replace('px', '')styT = +sty.top.replace('px', '')}document.onmousemove = function(e) {// 通过事件委托,计算移动的距离const l = e.clientX - disXconst t = e.clientY - disY// 移动当前元素dragDom.style.left = `${l + styL}px`dragDom.style.top = `${t + styT}px`// const dom = e.path.find(s => s.querySelector('.el-dialog')).children[0]//// if (dom.offsetTop < 0) {//   dragDom.style.top = `0px`// }// if (dom.offsetLeft < 0) {//   dragDom.style.left = `0px`// }// 将此时的位置传出去// binding.value({x:e.pageX,y:e.pageY})}document.onmouseup = function(e) {const dragDom = el.querySelector('.el-dialog')const offsetLeft = dragDom.offsetLeftconst offsetTop = dragDom.offsetTopconst left = Number(dragDom.style.left.replace('px', ''))const top = Number(dragDom.style.top.replace('px', ''))const windowWidth = window.innerWidthconst windowHeight = window.innerHeight - 50const offsetRight = offsetLeft + dragDom.offsetWidth - windowWidthconst offsetBottom = offsetTop + dragDom.offsetHeight - windowHeightif (offsetLeft < 0) {dragDom.style.left = (left - offsetLeft) + 'px'}if (offsetTop < 0) {dragDom.style.top = (top - offsetTop) + 'px'}if (offsetRight > 0) {dragDom.style.left = (left - offsetRight) + 'px'}if (offsetBottom > 0) {dragDom.style.top = (top - offsetBottom) + 'px'}document.onmousemove = nulldocument.onmouseup = null}}}}},

  监听 (打开关闭后 还原状态)

  watch: {dialogVisible(val) {if (val) {const el = this.$refs.xhzqDialog.$el.querySelector('.el-dialog')el.style.left = 0el.style.top = 0}}}

  样式

<style lang="scss">
.el-dialog{margin-top: 10vh!important;
}.no_select{-webkit-touch-callout: none; /* iOS Safari */-webkit-user-select: none; /* Chrome/Safari/Opera */-khtml-user-select: none; /* Konqueror */-moz-user-select: none; /* Firefox */-ms-user-select: none; /* Internet Explorer/Edge */user-select: none; /* Non-prefixed version, currently */}.isminimize{left: 20px;bottom: 20px;top: auto;right: auto;overflow:hidden;.el-dialog {margin: 0 !important;width: 240px !important;height: 40px;top: 0 !important;left: 0 !important;}.el-dialog__header{cursor: auto!important;.el-dialog__headerbtn {display: none;}}.dialogFooter{position: absolute;bottom: 0;}}.xhzqDialog {.is-fullscreen {width: 100% !important;left: 0 !important;top: 0 !important;margin-top: 0 !important;overflow:hidden;position: relative;.el-dialog__header{cursor: auto!important;}.el-dialog__body{height: 100%;.dialogBody{height:100%!important;max-height:none!important;padding-bottom:120px!important;}}.dialogFooter{position: absolute;bottom: 0;width: 100%;background: #fff;}}.el-dialog{.el-dialog__header{width: 100%;padding: 5px 20px 5px !important;display: flex;border-bottom: 1px solid #ccc;@extend .no_select;cursor: auto;.medium{width: 100%;height: 100%;display: flex;div{flex:1;}.centers{span{text-align: center;font-size:16px;color:#606266;}}.icons{display: flex;justify-content: flex-end;i{color:#5f6368;font-size: 18px!important;display: block;padding:0 7px;}i:hover{background: #dcdfe6;cursor: pointer;}.el-icon-close:hover{background: #f00;color:#fff;}}}.horn{width: 100%;height: 100%;display: flex;justify-content: space-between;div{i{color:#5f6368;font-size:20px!important;}}.lefts{flex:4;margin-top: 3px;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;span{font-size: 16px;color:#606266;}}.centers{flex:1;}.rights{flex:1;}i:hover{cursor: pointer;color:#000;}}.el-dialog__headerbtn {top: 0;font-size: 24px;}}.el-dialog__body{padding: 1px !important;.dialogBody{max-height: calc(80vh - 50px);box-shadow: inset 0px -2px 10px 1px #b0b3b2;overflow: auto;padding: 20px 25px 20px;background: #f7f9fc;&::-webkit-scrollbar {width: 4px;height: 8px;}&::-webkit-scrollbar-thumb {background: transparent;border-radius: 4px;}&:hover::-webkit-scrollbar-thumb {background: hsla(0,0%,53%,.4)}&:hover::-webkit-scrollbar-track {background: hsla(0,0%,53%,.1)}}.dialogFooter{padding: 10px 15px;border-top: 1px solid #ccc;text-align: right;.el-button{padding:7px 15px;}}}}.xhzqDialog{// display: flex;// justify-content: center;.el-select{width: 100%;}.el-date-editor{width: 100%;}}}
</style>

  

转载于:https://www.cnblogs.com/yasoPeng/p/10837449.html

实现el-dialog的拖拽,全屏,缩小功能相关推荐

  1. 打开google search,从taskbar拖拽全屏应用比如Google进入分屏,页面出现Launcher报错

    相关log: 08-17 18:34:33.907 11673 11673 E AndroidRuntime: FATAL EXCEPTION: main 08-17 18:34:33.907 116 ...

  2. Dialog 宽度占满全屏

    转载自:https://blog.csdn.net/sydmobile/article/details/83588708 Dialog 宽度占据全屏 关于如何自定义设置 Dialog 的大小,以及如何 ...

  3. 强大的jQuery幻灯片播放插件 支持全拼、拖拽和下载等功能

    强大的jQuery幻灯片播放插件 支持全拼.拖拽和下载等功能 在线演示 本地下载 posted @ 2018-11-29 11:30 栖息地 阅读(...) 评论(...) 编辑 收藏

  4. 为所有弹窗增加全屏切换功能

    1.现状 在开发两个管理系统,现在的页面20+,其中包含不少的弹窗.在项目开发过程中没人提过弹窗要全屏的事情,且在数据量较大的位置已经增加了可全屏的入口.但老板两次说为什么不给所有的弹窗增加全屏的功能 ...

  5. Android9全屏手势,国行三星S9系列开始推送安卓9.0 原生全屏手势功能来了

    原标题:国行三星S9系列开始推送安卓9.0 原生全屏手势功能来了 最近几天不少三星手机用户终于等来了跳票依旧的更新:包括三星S9.三星S9+.三星Note 9的国行版本终于获得了安卓9.0(Andro ...

  6. vue+openlayers中实现图片展示与图片的拖拽和放大缩小(一)

    前言: openlayers中渲染图片是有多种方法的, Icon ,Image 等等都可以实现将图片放到地图上面,但是操作图片的话,方法比较少了,这里是配合 ol-ext 来实现的. 相关资料: 1. ...

  7. Vue2 + ant design vue1.7.8版本 Table组件 手动拖拽、可伸缩列功能

    低版本的antd table组件 官网文档上有可伸缩列功能,但是用起来有很明显的bug,无法直接拿来用:接下来给大家提供一个手写的拖拽方案: 1.首先,写好v-table组件,这里最重要的就是tabl ...

  8. java 拖动图片放大_Android 图片拖拽、放大缩小的自定义控件

    需求:像相册中的图片跟随手指拖动,双指的放大和缩小,相册中拖出范围之后有弹回的动画,感觉上很圆润,很舒服,我写的例子中并没有加动画 思路:1.自定义DragImageView.java 2.自定义中先 ...

  9. echarts 弹出放大_Echarts图标增加全屏/放大功能

    需求描述: 客户爸爸在看某个echarts图表时,图标的数据很多,字看着很小,客户爸爸希望能双击放大某个图表.如下面这个图表字太小,太密. image.png 解决方式: 网上有不少方式是用Echar ...

  10. vue3实现鼠标左键拖拽画矩形框框选功能

    vue3 + elementuiPlus 实现鼠标左键拖拽画矩形框 框选列表功能,仿照桌面框选功能 效果如图: vue3鼠标框选 代码: <template><div class=& ...

最新文章

  1. Docker运行sonarqube (代码质量检测平台)
  2. matlab缺少某些变量,总提示缺少变量或函数
  3. 第二百五十八天 how can I 坚持
  4. 海量小文件的开源存储方案选型建议
  5. 项目分析-纷享车链AutoChain的数据保险柜解读
  6. reportmachine中怎样实现“数据注脚footer1”里面的内容在每页显示
  7. NM3200多用表校验仪
  8. cdrom是什么意思_CD-ROM是什么意思
  9. 大学物理复习笔记:刚体力学基础,动量矩
  10. 【读书笔记】《M型社会》大前研一
  11. 开始防破解--该死的杀毒软件
  12. 处理器后面的字母含义_Intel处理器背盖上的字母含义
  13. shiro自定义filter,anon不生效
  14. vue使用html2canvas jspdf实现pdf下载导出功能
  15. 更改微信浏览器页面标题
  16. Docker Image 基础使用命令
  17. 危害人类健康的饮食“凶徒” 都是人造的
  18. 为何苹果电脑虚拟机如此受欢迎
  19. 周志华机器学习--绪论
  20. 马化腾、任正非用“灰度”捕捉新商业机会

热门文章

  1. 原因代码10044-Erdos number Time limit exceeded
  2. UA OPTI570 量子力学33 Time-dependent Perturbation基础
  3. SQL Server 设置编辑所有行
  4. eclipse基本断点调试
  5. Asp.Net Session学习总结
  6. notepad++ 操作实例
  7. MacOS常用快捷键
  8. Jmeter学习系列----1 环境搭建
  9. 解决intellij IEDA mapper.xml文件警告以及could not autowire的错误提示
  10. 15.for循环的三个表达式是可以省略