@@ -1005,29 +1005,53 @@ document.addEventListener('DOMContentLoaded', async () => {
10051005 const tableWrapper = document . getElementById ( 'tableWrapper' ) ;
10061006 const scrollShadow = document . getElementById ( 'tableScrollShadow' ) ;
10071007 if ( tableContainer && scrollShadow ) {
1008+ let tableScrollWidth = 0 ;
1009+ let tableClientWidth = 0 ;
1010+ let scrollShadowFrame = null ;
1011+
1012+ const refreshScrollShadowMetrics = ( ) => {
1013+ tableScrollWidth = tableContainer . scrollWidth ;
1014+ tableClientWidth = tableContainer . clientWidth ;
1015+ } ;
1016+
10081017 const updateScrollShadow = ( ) => {
10091018 // 仅在表格可见时检测
10101019 if ( tableWrapper && tableWrapper . style . display === 'none' ) {
10111020 scrollShadow . classList . remove ( 'visible' ) ;
10121021 return ;
10131022 }
1014- // 检测是否有横向溢出且未滚动到最右侧
1015- const hasOverflow = tableContainer . scrollWidth > tableContainer . clientWidth + 1 ;
1016- const isAtEnd = tableContainer . scrollLeft + tableContainer . clientWidth >= tableContainer . scrollWidth - 4 ;
1023+ // scroll 期间只读 scrollLeft,宽度指标由内容变化/窗口变化时刷新,避免强制同步布局
1024+ const hasOverflow = tableScrollWidth > tableClientWidth + 1 ;
1025+ const isAtEnd = tableContainer . scrollLeft + tableClientWidth >= tableScrollWidth - 4 ;
10171026 if ( hasOverflow && ! isAtEnd ) {
10181027 scrollShadow . classList . add ( 'visible' ) ;
10191028 } else {
10201029 scrollShadow . classList . remove ( 'visible' ) ;
10211030 }
10221031 } ;
1023- tableContainer . addEventListener ( 'scroll' , updateScrollShadow , { passive : true } ) ;
1032+
1033+ const scheduleScrollShadowUpdate = ( ) => {
1034+ if ( scrollShadowFrame !== null ) return ;
1035+ scrollShadowFrame = requestAnimationFrame ( ( ) => {
1036+ scrollShadowFrame = null ;
1037+ updateScrollShadow ( ) ;
1038+ } ) ;
1039+ } ;
1040+
1041+ const refreshAndScheduleScrollShadowUpdate = ( ) => {
1042+ refreshScrollShadowMetrics ( ) ;
1043+ scheduleScrollShadowUpdate ( ) ;
1044+ } ;
1045+
1046+ refreshAndScheduleScrollShadowUpdate ( ) ;
1047+ tableContainer . addEventListener ( 'scroll' , scheduleScrollShadowUpdate , { passive : true } ) ;
10241048 // 使用 MutationObserver 监听表格内容变化
10251049 const observer = new MutationObserver ( ( ) => {
1026- setTimeout ( updateScrollShadow , 150 ) ;
1050+ setTimeout ( refreshAndScheduleScrollShadowUpdate , 150 ) ;
10271051 } ) ;
10281052 observer . observe ( tableContainer , { childList : true , subtree : true , characterData : true } ) ;
10291053 // 窗口大小变化时重新检测
1030- window . addEventListener ( 'resize' , updateScrollShadow , { passive : true } ) ;
1054+ window . addEventListener ( 'resize' , refreshAndScheduleScrollShadowUpdate , { passive : true } ) ;
10311055 }
10321056
10331057 // 点击外部关闭建议
0 commit comments