@@ -303,8 +303,47 @@ <h3>Sara Ahmed</h3>
303303 < p > Built with ❤️ for showcasing amazing front-end projects</ p >
304304 </ div >
305305 </ footer >
306+ < button id ="scrollToTopBtn " title ="Go to top "> ↑</ button >
307+ < script src ="script.js "> </ script >
308+ < script >
309+ const toggle = document . getElementById ( 'darkModeToggle' ) ;
310+ const body = document . body ;
311+ const icon = document . getElementById ( 'themeIcon' ) ;
306312
313+ // Load preference
314+ const savedTheme = localStorage . getItem ( 'theme' ) ;
315+ if ( savedTheme === 'dark' ) {
316+ body . classList . add ( 'dark-theme' ) ;
317+ icon . textContent = '☀️' ; // Sun in dark mode
318+ } else {
319+ icon . textContent = '🌙' ; // Moon in light mode
320+ }
307321
308- < script src ="script.js "> </ script >
309- </ body >
310- </ html >
322+ toggle . addEventListener ( 'click' , ( ) => {
323+ body . classList . toggle ( 'dark-theme' ) ;
324+ const theme = body . classList . contains ( 'dark-theme' ) ? 'dark' : 'light' ;
325+ localStorage . setItem ( 'theme' , theme ) ;
326+
327+ // Update icon
328+ icon . textContent = theme === 'dark' ? '☀️' : '🌙' ;
329+ </ script >
330+
331+
332+ < script >
333+ const scrollToTopBtn = document . getElementById ( "scrollToTopBtn" ) ;
334+
335+ // Show button when user scrolls down
336+ window . addEventListener ( "scroll" , ( ) => {
337+ scrollToTopBtn . style . display = window . scrollY > 300 ? "block" : "none" ;
338+ } ) ;
339+
340+ // Scroll to top smoothly
341+ scrollToTopBtn . addEventListener ( "click" , ( ) => {
342+ window . scrollTo ( {
343+ top : 0 ,
344+ behavior : "smooth"
345+ } ) ;
346+ } ) ;
347+
348+ </ script >
349+ </ body >
0 commit comments