From a7e784ba650fb359c39b7c64a318af63a2fe6925 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Mon, 16 Oct 2023 14:34:17 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=88=97=E8=A1=A8=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E5=88=B0=E5=BA=95=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/Pages/_Host.cshtml | 1 + Frontend/Shared/ChatZone.razor | 12 +++++++++++- Frontend/wwwroot/js/helper.js | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Frontend/wwwroot/js/helper.js diff --git a/Frontend/Pages/_Host.cshtml b/Frontend/Pages/_Host.cshtml index 9130ff0..afb25f3 100644 --- a/Frontend/Pages/_Host.cshtml +++ b/Frontend/Pages/_Host.cshtml @@ -32,5 +32,6 @@ + \ No newline at end of file diff --git a/Frontend/Shared/ChatZone.razor b/Frontend/Shared/ChatZone.razor index 5935261..737df11 100644 --- a/Frontend/Shared/ChatZone.razor +++ b/Frontend/Shared/ChatZone.razor @@ -1,8 +1,9 @@ @using Frontend.Models @using Katheryne.Abstractions +@inject IJSRuntime JsRuntime
-
+
@if (context.Left) @@ -76,6 +77,15 @@ base.OnInitialized(); } + protected override void OnAfterRender(bool firstRender) + { + if (!firstRender) + { + JsRuntime.InvokeVoidAsync("scrollToSection"); + } + base.OnAfterRender(firstRender); + } + private void SendMessageClicked() { if (string.IsNullOrWhiteSpace(MessageSending)) diff --git a/Frontend/wwwroot/js/helper.js b/Frontend/wwwroot/js/helper.js new file mode 100644 index 0000000..f71d50e --- /dev/null +++ b/Frontend/wwwroot/js/helper.js @@ -0,0 +1,7 @@ +function scrollToSection() { + let element = document.getElementById("chat-scroll-zone") + element.scrollTo({ + top: element.scrollHeight - element.offsetHeight, + behavior: "smooth" + }) +} \ No newline at end of file