Skip to content

Commit

Permalink
Smooth scrolling is back, again!...in some areas
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalmers committed Mar 7, 2024
1 parent 814750d commit 711b5ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@
}
}

async Task ScrollToMonth(int month)
async Task ScrollToMonth(int month, bool smooth = false)
{
logger.LogDebug($"Scrolling to month {month}");
logger.LogDebug($"Scrolling to month {month}, smooth: {smooth}");

await JSRuntime.InvokeVoidAsync("scrollToTopOfNestedElement", ".mood-grid", $"#mood-grid-month-{month}");
await JSRuntime.InvokeVoidAsync("scrollToTopOfNestedElement", ".page-body", $"#mood-grid-month-{month}", smooth ? "smooth" : "instant");
}

async Task ScrollToOpenToDate() => await ScrollToMonth(OpenToDate.Month);
async Task ScrollToOpenToDate() => await ScrollToMonth(OpenToDate.Month, true);

async Task HeaderClicked() => await ScrollToMonth(DateTime.Now.Month);

Expand Down
7 changes: 4 additions & 3 deletions JournalApp/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@

<script>
window.scrollToAbsoluteTop = () => {
document.scrollingElement.scrollTop = 0
document.scrollingElement.scrollTo({ top: 0, behavior: 'smooth' });
}

window.scrollToTopOfNestedElement = (ancestorSelector, descendantSelector) => {
document.scrollingElement.scrollTop = document.querySelector(descendantSelector).offsetTop - document.querySelector(ancestorSelector).offsetTop
window.scrollToTopOfNestedElement = (ancestorSelector, descendantSelector, scrollBehavior = 'smooth') => {
var elementTop = document.querySelector(descendantSelector).offsetTop - document.querySelector(ancestorSelector).offsetTop;
document.scrollingElement.scrollTo({ top: elementTop, behavior: scrollBehavior });
}
</script>

Expand Down

0 comments on commit 711b5ac

Please sign in to comment.