fix scroll bug, first message offsets on scroll
This commit is contained in:
parent
ce4a2f7c63
commit
8758a309fa
2 changed files with 25 additions and 18 deletions
|
|
@ -6,7 +6,6 @@ export default function useMessageRenderer() {
|
||||||
const { shiftAnimate, stackAnimate } = useRendererAnims();
|
const { shiftAnimate, stackAnimate } = useRendererAnims();
|
||||||
|
|
||||||
let messageList: NodeList;
|
let messageList: NodeList;
|
||||||
let modifier: string;
|
|
||||||
let message: HTMLElement | null;
|
let message: HTMLElement | null;
|
||||||
let messageOffset = { x: 0, y: 0 };
|
let messageOffset = { x: 0, y: 0 };
|
||||||
let shift = false;
|
let shift = false;
|
||||||
|
|
@ -21,7 +20,6 @@ export default function useMessageRenderer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function beforeEnter(el: SVGGElement): void {
|
function beforeEnter(el: SVGGElement): void {
|
||||||
modifier = el.className.baseVal.substring(0, 2);
|
|
||||||
const queryResult = document.querySelectorAll(".messageList");
|
const queryResult = document.querySelectorAll(".messageList");
|
||||||
if (queryResult.length) messageList = queryResult;
|
if (queryResult.length) messageList = queryResult;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,8 @@ export default function useScroller({ targetId }: {targetId: string}) {
|
||||||
let topBound: number;
|
let topBound: number;
|
||||||
|
|
||||||
const clampedScroll = computed(() => {
|
const clampedScroll = computed(() => {
|
||||||
const test = targetHeight.value;
|
if (targetHeight.value === 0) { return 0; }
|
||||||
if (test === 0) { return 0; }
|
topBound = -targetHeight.value + 440;
|
||||||
topBound = -test + 440;
|
|
||||||
return Math.max(topBound, Math.min(scroll.value, 0)) as number;
|
return Math.max(topBound, Math.min(scroll.value, 0)) as number;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -22,24 +21,34 @@ export default function useScroller({ targetId }: {targetId: string}) {
|
||||||
return `0 ${clampedScroll.value} 350 500`;
|
return `0 ${clampedScroll.value} 350 500`;
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
const getHeight = () => {
|
||||||
scrollTarget = document.getElementById(targetId);
|
if (scrollTarget) {
|
||||||
});
|
return scrollTarget.getBoundingClientRect().height as number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener(
|
const handleScrollEvent = (verticalScroll: number) => {
|
||||||
"wheel",
|
|
||||||
(e) => {
|
|
||||||
if (scrollTarget) {
|
if (scrollTarget) {
|
||||||
// get renderer height
|
|
||||||
targetHeight.value = scrollTarget.getBoundingClientRect().height;
|
|
||||||
// only scroll if renderer height is greater than main window
|
// only scroll if renderer height is greater than main window
|
||||||
if (targetHeight.value > 500) {
|
const heightResult = getHeight();
|
||||||
scroll.value += e.deltaY * 0.25;
|
if (heightResult) {
|
||||||
|
if (heightResult > 500) {
|
||||||
|
targetHeight.value = heightResult;
|
||||||
|
scroll.value += verticalScroll;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
{ passive: true }
|
|
||||||
);
|
onMounted(() => {
|
||||||
|
scrollTarget = document.getElementById(targetId);
|
||||||
|
if (scrollTarget) {
|
||||||
|
window.addEventListener("wheel", (e) => {
|
||||||
|
const verticalScroll = e.deltaY * 0.25;
|
||||||
|
handleScrollEvent(verticalScroll);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
scrollView
|
scrollView
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue