File tree Expand file tree Collapse file tree 2 files changed +12
-26
lines changed
src/BootstrapBlazor/Components/Scroll Expand file tree Collapse file tree 2 files changed +12
-26
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,5 @@ public partial class Scroll
6363 /// <summary>
6464 /// 滚动到底部
6565 /// </summary>
66- public async Task ScrollToBottom ( )
67- {
68- await InvokeVoidAsync ( "scrollToBottom" , Id ) ;
69- }
66+ public Task ScrollToBottom ( ) => InvokeVoidAsync ( "scrollToBottom" , Id ) ;
7067}
Original file line number Diff line number Diff line change 1- export function scrollToBottom ( id ) {
2- let el = document . getElementById ( id ) ;
3- const start = el . scrollTop ;
4- const end = el . scrollHeight ;
5- const distance = end - start ;
6- const duration = 500 ; // 动画持续时间(毫秒)
7- const startTime = performance . now ( ) ;
8-
9- function scrollStep ( currentTime ) {
10- const elapsed = currentTime - startTime ;
11- const progress = Math . min ( elapsed / duration , 1 ) ; // 确保进度不超过1
12- el . scrollTop = start + distance * progress ;
13-
14- if ( progress < 1 ) {
15- window . requestAnimationFrame ( scrollStep ) ;
16- }
17- }
18-
19- window . requestAnimationFrame ( scrollStep ) ;
20- }
21-
22- export function init ( id ) {
1+ export function init ( id ) {
232 const el = document . getElementById ( id )
243 if ( el === null ) {
254
265 }
276}
7+
8+ export function scrollToBottom ( id ) {
9+ const el = document . getElementById ( id ) ;
10+ const top = el . scrollHeight ;
11+ el . scrollTo ( {
12+ top,
13+ left : 0 ,
14+ behavior : "smooth"
15+ } ) ;
16+ }
You can’t perform that action at this time.
0 commit comments