问题描述
报错是这样的
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
dragging () {
this.keys = []
document.addEventListener(‘keydown’, this.draggingKeydown, false)
document.addEventListener(‘keyup’, this.draggingKeyup, false)
// 拖拽功能(主要是触发三个事件:onmousedownonmousemoveonmouseup)
let mindmapCont = this.$refs.mindmapCont
let mindmapBox = this.$refs.mindmapBox
if (!mindmapCont) {
return false
}
// 点击某物体时,用drag对象即可,move和up是全局区域,也就是整个文档通用,应该使用document对象而不是drag对象(否则,采用drag对象时物体只能往右方或下方移动)
mindmapCont.onmousedown = function (e) {
if (mindmapCont.classList.value.indexOf('move') < 0) {
return false
}
window.event ? (window.event.cancelBubble = true) : e.stopPropagation()
let event = e || window.event // 兼容ie浏览器
let diffX = event.clientX - mindmapBox.offsetLeft // 鼠标点击物体那一刻相对于物体左侧边框的距离=点击时的位置相对于浏览器最左边的距离-物体左边框相对于浏览器最左边的距离
let diffY = event.clientY - mindmapBox.offsetTop
/* 低版本ie bug:物体被拖出浏览器可是窗口外部时,还会出现滚动条,
解决方法是采用ie浏览器独有的2个方法setCapture()\releaseCapture(),这两个方法,
可以让鼠标滑动到浏览器外部也可以捕获到事件,而我们的bug就是当鼠标移出浏览器的时候,
限制超过的功能就失效了。用这个方法,即可解决这个问题。注:这两个方法用于onmousedown和onmouseup中 */
if (typeof mindmapCont.setCapture !== 'undefined') {
mindmapCont.setCapture()
}
mindmapCont.classList.add('moving')
document.onmousemove = function (e) {
window.event ? (window.event.cancelBubble = true) : e.stopPropagation()
let event = e || window.event // 兼容ie浏览器
let left = event.clientX - diffX
let top = event.clientY - diffY
// 移动时重新得到物体的距离,解决拖动时出现晃动的现象
mindmapBox.style.left = left + 'px'
mindmapBox.style.top = top + 'px'
}
document.onmouseup = function (e) { // 当鼠标弹起来的时候不再移动
window.event ? (window.event.cancelBubble = true) : e.stopPropagation()
mindmapCont.classList.remove('moving')
this.onmousemove = null
this.onmouseup = null // 预防鼠标弹起来后还会循环(即预防鼠标放上去的时候还会移动)
// 修复低版本ie bug
if (typeof mindmapCont.releaseCapture !== 'undefined') {
mindmapCont.releaseCapture()
}
}
}
}
你期待的结果是什么?实际看到的错误信息又是什么?