查询:
var isResizing = false,
lastDownX = 0;
$(function () {
var container = $('#container'),
top = $('#top-panel'),
handle = $('#drag');
handle.on('mousedown', function (e) {
isResizing = true;
lastDownX = e.clientY;
});
$(document).on('mousemove', function (e) {
// we don't want to do anything if we aren't resizing.
if (!isResizing)
return;
var offsetRight = top.height() + (e.clientY - container.offset().top);
top.css('top', offsetRight);
}).on('mouseup', function (e) {
// stop resizing
isResizing = false;
});
});
脚本:
var isResizing = false
// eslint-disable-next-line no-unused-vars
var lastDownX = 0
function resizeVerticallyInit () {
var top = document.querySelector('#topology-container')
var handle = document.querySelector('#drag')
handle.addEventListener('mousedown', function (e) {
isResizing = true
lastDownX = e.clientY
})
document.addEventListener('mousemove', function (e) {
// we don't want to do anything if we aren't resizing.
if (!isResizing) {
return
}
var offsetRight = top.height() + 20
document.querySelector('#topology-container').style.top = offsetRight
})
document.addEventListener('mouseup', function (e) {
// stop resizing
isResizing = false
})
}
mounted () {
...
resizeVerticallyInit()
}
如您所见,我在 mounted() 生命周期方法中的 Vue.js 组件中使用了 JavaScript 函数。
我试图转换它,但它不起作用。
首先我需要说:
// eslint-disable-next-line no-unused-vars
var lastDownX = 0
我不知道为什么它会抱怨 lastDownX 未被使用。
第二个是错误:
"[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'addEventListener' of null"
它抱怨:
handle.addEventListener('mousedown', function (e) {
isResizing = true
lastDownX = e.clientY
})
有人可以帮忙转换吗?
紫衣仙女
相关分类