Skip to content

Commit 291705a

Browse files
Smooth scrolling is back, again!...in some areas
1 parent de21009 commit 291705a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

JournalApp/Components/Pages/MoodGrid/MoodGridPage.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@
9696
}
9797
}
9898

99-
async Task ScrollToMonth(int month)
99+
async Task ScrollToMonth(int month, bool smooth = false)
100100
{
101-
logger.LogDebug($"Scrolling to month {month}");
101+
logger.LogDebug($"Scrolling to month {month}, smooth: {smooth}");
102102

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

106-
async Task ScrollToOpenToDate() => await ScrollToMonth(OpenToDate.Month);
106+
async Task ScrollToOpenToDate() => await ScrollToMonth(OpenToDate.Month, true);
107107

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

JournalApp/wwwroot/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333

3434
<script>
3535
window.scrollToAbsoluteTop = () => {
36-
document.scrollingElement.scrollTop = 0
36+
document.scrollingElement.scrollTo({ top: 0, behavior: 'smooth' });
3737
}
3838

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

0 commit comments

Comments
 (0)