vue.js怎么实现可拖拽菜单
发表于:2024-10-19 作者:千家信息网编辑
千家信息网最后更新 2024年10月19日,这篇文章主要介绍vue.js怎么实现可拖拽菜单,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!vue.js实现可拖拽菜单的方法:【import "@/assets/second.
千家信息网最后更新 2024年10月19日vue.js怎么实现可拖拽菜单
这篇文章主要介绍vue.js怎么实现可拖拽菜单,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
vue.js实现可拖拽菜单的方法:【import "@/assets/second.css";export default {name: "HelloWorld",directives: {move(el, bindings) {...】。
本文操作环境:windows10系统、vue.js 2.9、thinkpad t480电脑。
在给出正式的实现代码之前,我们要先来了解一点相关知识点。
知识点一:
vue中的自定义指令 directive
// 注册一个全局自定义指令 `v-focus`Vue.directive('focus', { // 当被绑定的元素插入到 DOM 中时…… inserted: function (el) { // 聚焦元素 el.focus() }})// 注册局部自定义指令directives: { focus: { // 指令的定义 inserted: function (el) { el.focus() } }}// 在此我们用的是局部
知识点二:js
onmousedown :鼠标按下事件 clientX :时鼠标指针相对于浏览器页面(或客户区)的水平坐标 document.getElementById :通过id获取节点 offsetWidth :获取的是盒子最终的宽 onmousemove :鼠标移动事件 onmouseup :鼠标释放事件
效果图:
页面代码:
右边自适应大小,黄色的为拖拽的按钮
样式代码:
.myBox{ width: 100%;; height: 700px; border: 1px solid red; display: flex;}#silderLeft{ width: 250px; height: 100%; background-color: #999; position: relative; /* overflow-y: auto; */}/* 拖动条 */.moveBtn{ height: 100%; width: 10px; /* opacity: 0; */ position: absolute; right: 0px; top: 0; cursor: col-resize; background-color: yellow;}.menuList{ background-color: yellowgreen; /* height: 120%; */}.silderRight{ height: 100%; background-color: sandybrown; flex: 1;}
可以修改自定义命令,设置一个最小拖拽宽度
directives: { move(el, bindings) { el.onmousedown = function(e) { var init = e.clientX; console.log('init',init); var parent = document.getElementById("sidebar"); var initWidth = parent.offsetWidth; _document.onmousemove = function(e) { var end = e.clientX; // end - init表示鼠标移动的距离 // end为鼠标移动的宽度,可用于设置最小宽度 if(end > 250){ var newWidth = end - init + initWidth; parent.style.width = newWidth + "px"; }else{ end = 250; // 最小宽度242 parent.style.width = 242 + "px"; } }; _document.onmouseup = function() { _document.onmousemove = _document.onmouseup = null; }; }; } }
以上是"vue.js怎么实现可拖拽菜单"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
鼠标
菜单
宽度
指令
知识
最小
事件
代码
知识点
移动
元素
内容
局部
篇文章
页面
价值
全局
兴趣
右边
命令
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
修改数据库数据中的年份
wifi直连摄像头不用服务器
我的世界登录服务器登录失效
植物教学软件开发必要性
流行的商用数据库还有版本
惠普580服务器管理口地址
中小学网络安全教育家庭
全栈数据库
软件开发人员做完软件不负责
什么类型网站服务器便宜
蓝盾杯网络安全报名
数据库表添加记录的命令
西安电子科大学科网络安全
软件开发合同装订
网络安全等级建设的必要性
上海数据网络技术服务工程
小黄车网络技术
北京+软件开发+日本
学生如何做到网络安全
河北服务器电源厂家定制
歌尔eea事业部软件开发
dhcp服务器设置 开启
电脑如何更快访问服务器
服务器硬件监控方案
solr操作数据库
服务器跑久时间变慢
登录淘宝服务器错误
成都抖音云控软件开发商
苹果tv激活服务器
求生之路无限火力服务器叫什么