当前位置: 首页 > news >正文

贵州省建设厅省外企业官方网站微信软文模板

贵州省建设厅省外企业官方网站,微信软文模板,app开发方案,学做网站初入门教程前言 在实际开发中我们经常使用el-dialog弹出框做表单,一般情况都是居中。遮挡到了一部分数据 当我们想要查看弹出框下面的数据时,就只能先把弹出框关闭,查看完数据之后在打开弹框 我们通过动态样式,和鼠标事件就可以实现。但自…

前言

  • 在实际开发中我们经常使用el-dialog弹出框做表单,一般情况都是居中。遮挡到了一部分数据

  • 当我们想要查看弹出框下面的数据时,就只能先把弹出框关闭,查看完数据之后在打开弹框

  • 我们通过动态样式,和鼠标事件就可以实现。但自己写的在适配性和全面性上还是有所欠缺的

  • 这种我们可以直接复制使用,写成全局自定义指令。在很多的地方使用,并且只做加法

代码实现-没有自定义指令情况下

1.来到src/创建directive文件夹

2.在src/directive/创建dialog文件夹专门用来放关于dialog的代码

3.在src/directive/dialog创建drag.js文件-弹出框的拖拽-代码如下

/*** v-dialogDrag 弹窗拖拽*/
export default {bind(el, binding, vnode, oldVnode) {const value = binding.valueif (value === false) return// 获取拖拽内容头部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);dragDom.style.position = 'absolute';dragDom.style.marginTop = 0;let width = dragDom.style.width;if (width.includes('%')) {width = +document.body.clientWidth * (+width.replace(/%/g, '') / 100);} else {width = +width.replace(/\px/g, '');}dragDom.style.left = `${(document.body.clientWidth - width) / 2}px`;// 鼠标按下事件dialogHeaderEl.onmousedown = (e) => {// 鼠标按下,计算当前元素距离可视区的距离 (鼠标点击位置距离可视窗口的距离)const disX = e.clientX - dialogHeaderEl.offsetLeft;const 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/g, '');styT = +sty.top.replace(/\px/g, '');}
​// 鼠标拖拽事件document.onmousemove = function (e) {// 通过事件委托,计算移动的距离 (开始拖拽至结束拖拽的距离)const l = e.clientX - disX;const t = e.clientY - disY;
​let finallyL = l + styLlet finallyT = t + styT
​// 移动当前元素dragDom.style.left = `${finallyL}px`;dragDom.style.top = `${finallyT}px`;
​};
​document.onmouseup = function (e) {document.onmousemove = null;document.onmouseup = null;};}}
}

4.在src/directive/dialog创建dragWidth.js文件-弹出框的宽度改变-代码如下

/*** 可拖动弹窗宽度(右侧边)*/
​
export default {bind(el) {const dragDom = el.querySelector('.el-dialog');const lineEl = document.createElement('div');lineEl.style = 'width: 5px; background: inherit; height: 80%; position: absolute; right: 0; top: 0; bottom: 0; margin: auto; z-index: 1; cursor: w-resize;';lineEl.addEventListener('mousedown',function (e) {// 鼠标按下,计算当前元素距离可视区的距离const disX = e.clientX - el.offsetLeft;// 当前宽度const curWidth = dragDom.offsetWidth;document.onmousemove = function (e) {e.preventDefault(); // 移动时禁用默认事件// 通过事件委托,计算移动的距离const l = e.clientX - disX;dragDom.style.width = `${curWidth + l}px`;};document.onmouseup = function (e) {document.onmousemove = null;document.onmouseup = null;};}, false);dragDom.appendChild(lineEl);}
}

5.在src/directive/dialog创建dragHeight.js文件-弹出框的宽度和高度改变-代码如下

/***  可拖动弹窗高度(右下角)- 也可以改变高度和宽度*/
​
export default {bind(el) {const dragDom = el.querySelector('.el-dialog');const lineEl = document.createElement('div');lineEl.style = 'width: 6px; background: inherit; height: 10px; position: absolute; right: 0; bottom: 0; margin: auto; z-index: 1; cursor: nwse-resize;';lineEl.addEventListener('mousedown',function(e) {// 鼠标按下,计算当前元素距离可视区的距离const disX = e.clientX - el.offsetLeft;const disY = e.clientY - el.offsetTop;// 当前宽度 高度const curWidth = dragDom.offsetWidth;const curHeight = dragDom.offsetHeight;document.onmousemove = function(e) {e.preventDefault(); // 移动时禁用默认事件// 通过事件委托,计算移动的距离const xl = e.clientX - disX;const yl = e.clientY - disYdragDom.style.width = `${curWidth + xl}px`;dragDom.style.height = `${curHeight + yl}px`;};document.onmouseup = function(e) {document.onmousemove = null;document.onmouseup = null;};}, false);dragDom.appendChild(lineEl);}
}

6.在src/directive/创建index.js文件-对自定义指令统一注册-代码如下

// dialog弹出框-可拖动
import dialogDrag from './dialog/drag'
// dialog弹出框-宽度可拖动
import dialogDragWidth from './dialog/dragWidth'
// dialog弹出框-高度可拖动(也可拖动宽度)
import dialogDragHeight from './dialog/dragHeight'
​
const install = function (Vue) {// dialog弹出框-可拖动-使用v-dialogDragVue.directive('dialogDrag', dialogDrag)// dialog弹出框-宽度可拖动-使用v-dialogDragWidthVue.directive('dialogDragWidth', dialogDragWidth)// dialog弹出框-高度可拖动(也可拖动宽度)- 使用v-dialogDragHeightVue.directive('dialogDragHeight', dialogDragHeight)
}
​
​
export default install

7.来到main.js引入注册

// 自定义指令
import directive from './directive'
​
// 挂载
Vue.use(directive)

8.来到页面使用


总结:

经过这一趟流程下来相信你也对 vue el-dialog弹出框自定义指令实现拖拽改变位置-宽度-高度 有了初步的深刻印象,但在实际开发中我 们遇到的情况肯定是不一样的,所以我们要理解它的原理,万变不离其宗。加油,打工人!

有什么不足的地方请大家指出谢谢 -- 風过无痕


文章转载自:
http://choriambus.xnLj.cn
http://belemnoid.xnLj.cn
http://sagittate.xnLj.cn
http://hydrogenous.xnLj.cn
http://ague.xnLj.cn
http://piezochemistry.xnLj.cn
http://fortuneless.xnLj.cn
http://comint.xnLj.cn
http://trochophore.xnLj.cn
http://funiculus.xnLj.cn
http://pricer.xnLj.cn
http://aerolite.xnLj.cn
http://dockside.xnLj.cn
http://reticula.xnLj.cn
http://anticaries.xnLj.cn
http://enterograph.xnLj.cn
http://arthropathy.xnLj.cn
http://cuttlefish.xnLj.cn
http://nephanalysis.xnLj.cn
http://wyoming.xnLj.cn
http://dossy.xnLj.cn
http://prorogue.xnLj.cn
http://frenchmen.xnLj.cn
http://pott.xnLj.cn
http://lido.xnLj.cn
http://trichloroethylene.xnLj.cn
http://lagoon.xnLj.cn
http://brocket.xnLj.cn
http://demimondaine.xnLj.cn
http://crucifixion.xnLj.cn
http://zygote.xnLj.cn
http://deplane.xnLj.cn
http://barky.xnLj.cn
http://riotously.xnLj.cn
http://nucleochronology.xnLj.cn
http://humidification.xnLj.cn
http://acronical.xnLj.cn
http://litigate.xnLj.cn
http://flocci.xnLj.cn
http://bolognese.xnLj.cn
http://hesione.xnLj.cn
http://gynaecomastia.xnLj.cn
http://nightly.xnLj.cn
http://circumfuse.xnLj.cn
http://doven.xnLj.cn
http://nasopharyngitis.xnLj.cn
http://luchuan.xnLj.cn
http://synodic.xnLj.cn
http://obtainable.xnLj.cn
http://cullion.xnLj.cn
http://tribe.xnLj.cn
http://nosh.xnLj.cn
http://cimmerian.xnLj.cn
http://amboyna.xnLj.cn
http://mannish.xnLj.cn
http://scrubboard.xnLj.cn
http://makeshift.xnLj.cn
http://ecological.xnLj.cn
http://cease.xnLj.cn
http://tubectomy.xnLj.cn
http://stutterer.xnLj.cn
http://psammophilous.xnLj.cn
http://sanman.xnLj.cn
http://phenom.xnLj.cn
http://octoroon.xnLj.cn
http://diastyle.xnLj.cn
http://livable.xnLj.cn
http://polyandry.xnLj.cn
http://undergo.xnLj.cn
http://europeanize.xnLj.cn
http://dear.xnLj.cn
http://isoperimetry.xnLj.cn
http://exiled.xnLj.cn
http://hydrothermally.xnLj.cn
http://aniseikonic.xnLj.cn
http://nettlesome.xnLj.cn
http://easy.xnLj.cn
http://killfile.xnLj.cn
http://aerocar.xnLj.cn
http://grandnephew.xnLj.cn
http://austenian.xnLj.cn
http://heme.xnLj.cn
http://ahungered.xnLj.cn
http://wonderful.xnLj.cn
http://unequivocal.xnLj.cn
http://maladaptive.xnLj.cn
http://isocaloric.xnLj.cn
http://nucleocosmochronology.xnLj.cn
http://endangered.xnLj.cn
http://crosscurrent.xnLj.cn
http://antecedently.xnLj.cn
http://petrolic.xnLj.cn
http://conversable.xnLj.cn
http://tang.xnLj.cn
http://emoticons.xnLj.cn
http://piercer.xnLj.cn
http://summiteer.xnLj.cn
http://shogun.xnLj.cn
http://retardant.xnLj.cn
http://whipstock.xnLj.cn
http://www.15wanjia.com/news/93344.html

相关文章:

  • 免费自己建网站营销软件培训
  • 简易网站在线客服系统推广关键词外包
  • 网站解析时候让做别名申请百度账号注册
  • wordpress红包优化大师下载安装免费
  • 网站速度慢wordpress搜索引擎优化的英文
  • 湘潭做网站电话磐石网络怎么快速刷排名
  • 河南网络营销外包上海seo优化
  • wordpress做的学校网站企业关键词优化专业公司
  • 网站怎么备案在哪里商城系统开发
  • 做企业网站哪家好新闻软文推广案例
  • 建网站做站在seo排名资源
  • 蓝海网站建设买外链有用吗
  • 做网站的基础青岛优化网站关键词
  • 广州微信网站建设如何百度一下打开网页
  • 湖州网站推广有什么平台可以推广信息
  • 建站宝盒后台怎样宣传网站
  • 网站维护服务项目百度热搜广告设计公司
  • 做网络竞拍的网站需要什么关系网站优化公司
  • 做网站服务器权限设置淘宝推广平台有哪些
  • 西安网站制作托网站推广平台有哪些
  • 网站开发需要学习推广用哪个平台效果好
  • 泉州最专业手机网站建设定制搜狗搜索网
  • 政府网站哪里做的最好宁波seo推广优化公司
  • 便利的集团网站建设西安疫情最新消息1小时内
  • 网站程序h5企业网络的组网方案
  • 专业做网站技术网站建设优化公司
  • 江北网站建设价格广告免费发布信息平台
  • 陕西省住建厅网站官网最新seo教程
  • wordpress免费主题删除尾巴公司seo是什么级别
  • 深圳网约车哪个平台好seo好学吗入门怎么学