File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed
Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -43,16 +43,25 @@ export const Overview = (pr: PullRequest) => {
4343 // Initially ensure title is not stuck
4444 title . classList . remove ( 'stuck' ) ;
4545
46- // Use scroll event to detect when title actually becomes sticky
46+ // Small threshold to account for sub-pixel rendering
47+ const STICKY_THRESHOLD = 1 ;
48+
49+ // Use scroll event with requestAnimationFrame to detect when title becomes sticky
4750 // Check if the title's top position is at the viewport top (sticky position)
51+ let ticking = false ;
4852 const handleScroll = ( ) => {
49- const rect = title . getBoundingClientRect ( ) ;
50- // Title is stuck when its top is at position 0 (sticky top: 0)
51- // Add small threshold to account for sub-pixel rendering
52- if ( rect . top <= 1 ) {
53- title . classList . add ( 'stuck' ) ;
54- } else {
55- title . classList . remove ( 'stuck' ) ;
53+ if ( ! ticking ) {
54+ window . requestAnimationFrame ( ( ) => {
55+ const rect = title . getBoundingClientRect ( ) ;
56+ // Title is stuck when its top is at position 0 (sticky top: 0)
57+ if ( rect . top <= STICKY_THRESHOLD ) {
58+ title . classList . add ( 'stuck' ) ;
59+ } else {
60+ title . classList . remove ( 'stuck' ) ;
61+ }
62+ ticking = false ;
63+ } ) ;
64+ ticking = true ;
5665 }
5766 } ;
5867
You can’t perform that action at this time.
0 commit comments