vue视频框文本框随意拖拽

// 悬浮按钮组件 <template> <div style="position:relative;"> <div class="button-box" v-drag draggable="false"> <div class="btn-bg-img" @dblclick="openBox"></div> <div class="font-box">{{ text }}</div> </div> </div> </template> <script> export default { components: {caseInfo}, props: ['caseID'], data () { return { text: '双击显示案件详情', isOpen: false, isMove: false } }, methods: { openBox () { console.log('双击') }, mousedowm (e) { // 鼠标按下时的鼠标所在的X,Y坐标 this.mouseDownX = e.pageX this.mouseDownY = e.pageY // 初始位置的X,Y 坐标 // this.initX = obj.offsetLeft; // this.initY = obj.offsetTop; console.log('e', e) // 表示鼠标已按下 this.flag = true }, mousemove (e) { if (this.flag) { console.log('e :', e) } } }, directives: { drag (el) { let oDiv = el // 当前元素 // let self = this // 上下文 // 禁止选择网页上的文字 document.onselectstart = function () { return false } oDiv.onmousedown = function (e) { // 鼠标按下,计算当前元素距离可视区的距离 let disX = e.clientX - oDiv.offsetLeft let disY = e.clientY - oDiv.offsetTop document.onmousemove = function (e) { // 通过事件委托,计算移动的距离 let l = e.clientX - disX let t = e.clientY - disY // 移动当前元素 oDiv.style.left = l + 'px' oDiv.style.top = t + 'px' } document.onmouseup = function (e) { document.onmousemove = null document.onmouseup = null } // return false不加的话可能导致黏连,就是拖到一个地方时div粘在鼠标上不下来,相当于onmouseup失效 return false } } } } </script> <style scoped> .button-box { width: 80px; border-radius: 50%; position: fixed; bottom: 80px; right: 50px; padding-left: 15px; padding-top: 8px; cursor: pointer; opacity: 0.7; z-index: 888; } .btn-bg-img { width: 80px; height: 80px; background-image: url('../../../static/images/click.png'); background-size: cover; } .button-box:hover { color: white; opacity: 1; } .font-box { width: 80px; color: #3193ef; text-align: center; } </style>

转载地址:https://www.jianshu.com/p/9816e8b9040e

 
 

__EOF__

本文作者皮军旗
本文链接https://www.cnblogs.com/pijunqi/p/14217485.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   皮军旗  阅读(428)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示