1- import React , { ReactNode , useState } from 'react' ;
1+ import React , { ReactNode , useEffect , useState } from 'react' ;
22import type { MenuDataItem } from '@ant-design/pro-components' ;
33import { PageContainer , ProLayout } from '@ant-design/pro-components' ;
44import { useLocation , Link } from 'react-router-dom' ;
@@ -174,6 +174,20 @@ interface ICustomLayoutProps {
174174const CustomLayout = ( { children } : ICustomLayoutProps ) => {
175175 const location = useLocation ( ) ;
176176
177+ const [ scrollPercent , setScrollPercent ] = useState ( 0 ) ;
178+
179+ useEffect ( ( ) => {
180+ const handleScroll = ( ) => {
181+ const scrollTop = window . scrollY || document . documentElement . scrollTop ;
182+ const scrollHeight = document . documentElement . scrollHeight - window . innerHeight ;
183+ const scrolled = ( scrollTop / scrollHeight ) * 100 ;
184+ setScrollPercent ( scrolled ) ;
185+ } ;
186+
187+ window . addEventListener ( 'scroll' , handleScroll , { passive : true } ) ;
188+ return ( ) => window . removeEventListener ( 'scroll' , handleScroll ) ;
189+ } , [ ] ) ;
190+
177191 return (
178192 < ProLayout
179193 logo = { logo }
@@ -192,7 +206,21 @@ const CustomLayout = ({ children }: ICustomLayoutProps) => {
192206 >
193207 < PageContainer header = { { title : true } } >
194208 < Affix offsetTop = { 0 } >
195- < SearchBar />
209+ < div style = { { position : 'relative' } } >
210+ < div
211+ style = { {
212+ position : 'absolute' ,
213+ top : 0 ,
214+ left : 0 ,
215+ height : 4 ,
216+ width : `${ scrollPercent } %` ,
217+ background : '#1890ff' ,
218+ transition : 'width 0.1s ease-out' ,
219+ zIndex : 9999 ,
220+ } }
221+ />
222+ < SearchBar />
223+ </ div >
196224 </ Affix >
197225 < div style = { { padding : 16 , background : 'transparent' } } >
198226 { children }
0 commit comments