@@ -133,52 +133,40 @@ <h1>Ice Star</h1>
133133 < div id ="bottomDivider "> </ div >
134134
135135 < script src ="index.js?v=8 "> </ script >
136+
136137< script >
137- window . addEventListener ( "load" , ( ) => {
138- const container = document . getElementById ( "topDivider" ) ;
139- if ( ! container ) return ;
140-
141- // 1. Initiate primary scroll into view
142- container . scrollIntoView ( {
143- behavior : "smooth" ,
144- block : "start"
145- } ) ;
146-
147- let animationFrameId ;
148- let stableCount = 0 ;
149- let lastPosition = window . scrollY ;
150-
151- // 2. Loop and wait for the initial scroll to complete stably
152- function verifyAndOffsetScroll ( ) {
153- const currentPosition = window . scrollY ;
154-
155- // If the scroll position hasn't changed from the last frame, it is settling
156- if ( currentPosition === lastPosition ) {
157- stableCount ++ ;
158-
159- // Once verified stable for 5 continuous frames, apply the final offset
160- if ( stableCount >= 5 ) {
161- window . scrollBy ( {
162- top : 170 ,
138+ ( function ( ) {
139+ const OFFSET = 170 ;
140+ const TARGET_ID = "topDivider" ;
141+
142+ window . addEventListener ( "load" , ( ) => {
143+
144+ // Don't auto-scroll inside an iframe.
145+ if ( window . self !== window . top ) {
146+ return ;
147+ }
148+
149+ // Wait until layout settles.
150+ requestAnimationFrame ( ( ) => {
151+ requestAnimationFrame ( ( ) => {
152+
153+ const target = document . getElementById ( TARGET_ID ) ;
154+ if ( ! target ) return ;
155+
156+ const y = target . getBoundingClientRect ( ) . top +
157+ window . pageYOffset +
158+ OFFSET ;
159+
160+ window . scrollTo ( {
161+ top : y ,
163162 behavior : "smooth"
164163 } ) ;
165-
166- // CRITICAL FIX: Kill the loop completely so it never recurs or loops infinitely
167- cancelAnimationFrame ( animationFrameId ) ;
168- return ;
169- }
170- } else {
171- // Reset counter if still actively moving to the initial anchor
172- stableCount = 0 ;
173- }
174164
175- lastPosition = currentPosition ;
176- animationFrameId = requestAnimationFrame ( verifyAndOffsetScroll ) ;
177- }
165+ } ) ;
166+ } ) ;
178167
179- // Begin monitoring frame states
180- animationFrameId = requestAnimationFrame ( verifyAndOffsetScroll ) ;
181- } ) ;
168+ } , { once : true } ) ;
169+ } ) ( ) ;
182170</ script >
183171
184172
0 commit comments