|
|
|
@ -28,6 +28,35 @@ export default defineComponent({ |
|
|
|
}); |
|
|
|
const barStore = ref<Recordable>({}); |
|
|
|
const cursorDown = ref(); |
|
|
|
|
|
|
|
const mouseMoveDocumentHandler = (e: any) => { |
|
|
|
if (cursorDown.value === false) { |
|
|
|
return; |
|
|
|
} |
|
|
|
const prevPage = barStore.value[bar.value.axis]; |
|
|
|
|
|
|
|
if (!prevPage) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const offset = |
|
|
|
(instance?.vnode.el?.getBoundingClientRect()[bar.value.direction] - e[bar.value.client]) * |
|
|
|
-1; |
|
|
|
const thumbClickPosition = thumb.value[bar.value.offset] - prevPage; |
|
|
|
const thumbPositionPercentage = |
|
|
|
((offset - thumbClickPosition) * 100) / instance?.vnode.el?.[bar.value.offset]; |
|
|
|
wrap.value[bar.value.scroll] = |
|
|
|
(thumbPositionPercentage * wrap.value[bar.value.scrollSize]) / 100; |
|
|
|
}; |
|
|
|
|
|
|
|
const startDrag = (e: any) => { |
|
|
|
e.stopImmediatePropagation(); |
|
|
|
cursorDown.value = true; |
|
|
|
on(document, 'mousemove', mouseMoveDocumentHandler); |
|
|
|
on(document, 'mouseup', mouseUpDocumentHandler); |
|
|
|
document.onselectstart = () => false; |
|
|
|
}; |
|
|
|
|
|
|
|
const clickThumbHandler = (e: any) => { |
|
|
|
// prevent click event of right button
|
|
|
|
if (e.ctrlKey || e.button === 2) { |
|
|
|
@ -51,29 +80,6 @@ export default defineComponent({ |
|
|
|
wrap.value[bar.value.scroll] = |
|
|
|
(thumbPositionPercentage * wrap.value[bar.value.scrollSize]) / 100; |
|
|
|
}; |
|
|
|
const startDrag = (e: any) => { |
|
|
|
e.stopImmediatePropagation(); |
|
|
|
cursorDown.value = true; |
|
|
|
on(document, 'mousemove', mouseMoveDocumentHandler); |
|
|
|
on(document, 'mouseup', mouseUpDocumentHandler); |
|
|
|
document.onselectstart = () => false; |
|
|
|
}; |
|
|
|
|
|
|
|
const mouseMoveDocumentHandler = (e: any) => { |
|
|
|
if (cursorDown.value === false) return; |
|
|
|
const prevPage = barStore.value[bar.value.axis]; |
|
|
|
|
|
|
|
if (!prevPage) return; |
|
|
|
|
|
|
|
const offset = |
|
|
|
(instance?.vnode.el?.getBoundingClientRect()[bar.value.direction] - e[bar.value.client]) * |
|
|
|
-1; |
|
|
|
const thumbClickPosition = thumb.value[bar.value.offset] - prevPage; |
|
|
|
const thumbPositionPercentage = |
|
|
|
((offset - thumbClickPosition) * 100) / instance?.vnode.el?.[bar.value.offset]; |
|
|
|
wrap.value[bar.value.scroll] = |
|
|
|
(thumbPositionPercentage * wrap.value[bar.value.scrollSize]) / 100; |
|
|
|
}; |
|
|
|
|
|
|
|
function mouseUpDocumentHandler() { |
|
|
|
cursorDown.value = false; |
|
|
|
|