scroll top fixies

This commit is contained in:
Peter Olu 2022-04-25 13:50:57 +01:00
parent e9744cbc79
commit a5c74c4372

View File

@ -216,11 +216,13 @@ export default defineComponent({
if (element.isIntersecting && element.intersectionRatio > 0) { if (element.isIntersecting && element.intersectionRatio > 0) {
setTimeout(() => { setTimeout(() => {
currentItem.value = element.target.id; currentItem.value = element.target.id;
console.log('219-CurrentEl:',currentItem.value);
}, 200); }, 200);
} }
}); });
}); });
firstItem.value = document?.getElementById(`tabitem${graphs[0].i}`) firstItem.value = document?.getElementById(`tabitem${graphs[0].i}`);
document.querySelectorAll(".tabitem").forEach((element) => { document.querySelectorAll(".tabitem").forEach((element) => {
observer.observe(element); observer.observe(element);
}); });
@ -302,13 +304,14 @@ export default defineComponent({
); );
} }
function scrollToFirstGraph(scrollUp: boolean) { function scrollToFirstGraph(scrollUp: boolean) {
const graphs = JSON.parse(JSON.stringify(dashboardStore.currentTabItems)); const noNextEl =
const thereisNextEl = document?.getElementById(`${currentItem.value}`) !== null document?.getElementById(`${currentItem.value}`)?.nextElementSibling === null;
if (scrollUp && !thereisNextEl) { if (scrollUp && noNextEl) {
console.log(firstItem.value) console.log(firstItem.value)
firstItem.value.scrollIntoView(); firstItem.value.scrollIntoView();
} }
} }
document.body.addEventListener("click", handleClick, false); document.body.addEventListener("click", handleClick, false);
watch( watch(
() => dashboardStore.activedGridItem, () => dashboardStore.activedGridItem,
@ -327,27 +330,26 @@ export default defineComponent({
); );
onMounted(() => { onMounted(() => {
tabObserveContainer?.value?.addEventListener("scroll", (e: Event) => { tabObserveContainer?.value?.addEventListener("scroll", (e: Event) => {
const prevScrollY = tabObserveContainer.value.scrollTop
if (refScrollTimeOut.value) { if (refScrollTimeOut.value) {
clearTimeout(refScrollTimeOut.value) clearTimeout(refScrollTimeOut.value);
} }
// console.log("WindowScrollY Outside:", tabObserveContainer.value);
refScrollTimeOut.value = window.setTimeout(() => { refScrollTimeOut.value = window.setTimeout(() => {
if ( // console.log('prevScroll',prevScrollY, 'currentID:', currentItem.value);
tabObserveContainer.value?.scrollTop > currentScrollY.value || if(tabObserveContainer.value?.scrollTop > currentScrollY.value ||
tabObserveContainer.value?.scrollTop === currentScrollY.value tabObserveContainer.value?.scrollTop === currentScrollY.value)
) { {
scrollToFirstGraph(true) console.log(tabObserveContainer.value?.scrollTop, currentScrollY.value)
console.log("Scrolled Down!") setTimeout(() =>{
} scrollToFirstGraph(true)
currentScrollY.value = tabObserveContainer.value?.scrollTop },200)
console.log("CurrentScrollY:", document?.getElementById(`${currentItem.value}`)); // console.log("scrolled Down:", document?.getElementById(`${currentItem.value}`)?.nextElementSibling, firstItem.value)
}
currentScrollY.value = tabObserveContainer.value?.scrollTop
}, 100); }, 100);
}); });
tabRef?.value["parentElement"]?.classList?.toggle("item"); tabRef?.value["parentElement"]?.classList?.toggle("item");
if (dashboardStore.fullView) {
// console.log("Tab Osbercve:", tabObserveContainer);
}
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
observeItems(true); observeItems(true);