We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
需要做一个客服悬窗 可拖拽 可点击展开客服聊天界面 我的结构是div 包 img
禁止拖拽
不能跟随鼠标切有延时
div+background-image
[0,document.documentElement.clientHeight - el.offsetHeight]
[0,document.documentElement.clientWidth - el.offsetWidth]
[onmousedown,onmousemove,onmouseup,click]
onmousemove=>onmouseup
const Drag: any = {} Drag.install = (Vue, options = {}) => { Vue.directive('drag', { inserted(el,binding) { const { id } = binding.value el.onmousedown = function(ev) { // 用元素距离视窗的X、Y坐标,减去el元素最近的相对定位父元素的left、top值 var sX = ev.clientX - el.offsetLeft var sY = ev.clientY - el.offsetTop // 不断地更新元素的left、top值 document.onmousemove = function(ev) { el.setAttribute('data-flag', false) let top = ev.clientY - sY if (top < 0) { top = 0 } else if ( top > document.documentElement.clientHeight - el.offsetHeight ) { top = document.documentElement.clientHeight - el.offsetHeight } el.style.top = top + 'px' } const firstTime = new Date().getTime() document.onmouseup = function(event) { document.onmousemove = null document.onmouseup = null const lastTime = new Date().getTime() if (lastTime - firstTime < 200) { // 点击 el.setAttribute('data-flag', true) document.getElementById(id).click() } } } } }) } export default Drag
<div class="darg-smart" v-drag="{id:'smart'}" @load="changeImg(this)"> <div class="img-smart" v-show="!showSamrt"></div> </div> <div id="smart" @click="showSamrt = true"></div> <SmartCustomerService v-if="showSamrt" @weClose="onClose" />
The text was updated successfully, but these errors were encountered:
No branches or pull requests
封装成指令
背景
踩坑
禁止拖拽
代码已经加上 dragable=true 然并卵不能跟随鼠标切有延时
)代码思路
div+background-image
[0,document.documentElement.clientHeight - el.offsetHeight]
[0,document.documentElement.clientWidth - el.offsetWidth]
[onmousedown,onmousemove,onmouseup,click]
只枚举我下面用到的onmousemove=>onmouseup
过程的时间间隔 我这里是200ms使用
The text was updated successfully, but these errors were encountered: