scroll to top works

This commit is contained in:
Peter Olu 2022-04-24 18:43:02 +01:00
parent 43e7c2c4ff
commit 1cf0bfb474

View File

@ -190,6 +190,9 @@ export default defineComponent({
const tabObserveContainer = ref<any>(null); const tabObserveContainer = ref<any>(null);
const currentItem = ref(""); const currentItem = ref("");
const lastItem = ref(""); const lastItem = ref("");
const refScrollTimeOut = ref();
const currentScrollY = ref(0);
const l = dashboardStore.layout.findIndex( const l = dashboardStore.layout.findIndex(
(d: LayoutConfig) => d.i === props.data.i (d: LayoutConfig) => d.i === props.data.i
); );
@ -313,6 +316,12 @@ export default defineComponent({
dashboardStore.setCurrentTabItems( dashboardStore.setCurrentTabItems(
dashboardStore.layout[l].children[activeTabIndex.value].children dashboardStore.layout[l].children[activeTabIndex.value].children
); );
}
function scrollToFirstGraph(scrollUp: boolean) {
const graphs = JSON.parse(JSON.stringify(dashboardStore.currentTabItems));
if (scrollUp) {
document?.getElementById(`tabitem${graphs[0].i}`)?.scrollIntoView();
}
} }
document.body.addEventListener("click", handleClick, false); document.body.addEventListener("click", handleClick, false);
watch( watch(
@ -332,9 +341,19 @@ export default defineComponent({
); );
onMounted(() => { onMounted(() => {
tabObserveContainer?.value?.addEventListener("scroll", (e: Event) => { tabObserveContainer?.value?.addEventListener("scroll", (e: Event) => {
// debounce(() => { if (refScrollTimeOut.value) {
// console.log("Yeah!"); clearTimeout(refScrollTimeOut.value)
// }, 100); }
// console.log("WindowScrollY Outside:", tabObserveContainer.value);
refScrollTimeOut.value = window.setTimeout(() => {
if (tabObserveContainer.value?.scrollTop === currentScrollY.value) {
scrollToFirstGraph(true)
console.log("Scrolled Down!")
}
currentScrollY.value = tabObserveContainer.value?.scrollTop
console.log("CurrentScrollY:", currentScrollY.value);
}, 100);
}); });
tabRef?.value["parentElement"]?.classList?.toggle("item"); tabRef?.value["parentElement"]?.classList?.toggle("item");
if (dashboardStore.fullView) { if (dashboardStore.fullView) {