Skip to content

Commit

Permalink
Smooth scrolling is back!
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalmers committed Feb 7, 2024
1 parent 10a4996 commit 9b92b20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
async Task ScrollToTop()
{
logger.LogDebug("Scrolling to top");
await JSRuntime.InvokeVoidAsync("scrollToAbsoluteTop");
await JSRuntime.InvokeVoidAsync("scrollToTopOfPage");
}

async Task ScrollToGroup(string key)
Expand Down
7 changes: 4 additions & 3 deletions JournalApp/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
<script src="_content/MudBlazor/MudBlazor.min.js"></script>

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

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

Expand Down

0 comments on commit 9b92b20

Please sign in to comment.