@@ -338,6 +338,58 @@ document.addEventListener('DOMContentLoaded', function() {
338338
339339 // Initialize carousel
340340 carousel . init ( ) ;
341+
342+ // Get the button elements from the HTML
343+ const scrollTopBtn = document . getElementById ( 'scrollTopBtn' ) ;
344+ const scrollBottomBtn = document . getElementById ( 'scrollBottomBtn' ) ;
345+
346+ // Function to handle the visibility of both scroll buttons
347+ const handleScrollButtons = ( ) => {
348+ const scrollHeight = document . documentElement . scrollHeight ;
349+ const clientHeight = document . documentElement . clientHeight ;
350+ const scrollPosition = window . scrollY ;
351+
352+ // --- Scroll to Top Button Logic ---
353+ // Show the button if user has scrolled down more than 300px
354+ if ( scrollPosition > 300 ) {
355+ scrollTopBtn . classList . add ( 'visible' ) ;
356+ } else {
357+ scrollTopBtn . classList . remove ( 'visible' ) ;
358+ }
359+
360+ // --- Scroll to Bottom Button Logic ---
361+ // Show the button if user is near the top, but hide it when they get close to the bottom
362+ const isNearBottom = scrollPosition + clientHeight >= scrollHeight - 300 ;
363+ if ( scrollPosition > 100 && ! isNearBottom ) {
364+ scrollBottomBtn . classList . add ( 'visible' ) ;
365+ } else {
366+ scrollBottomBtn . classList . remove ( 'visible' ) ;
367+ }
368+ } ;
369+
370+ // --- Click Event Listeners ---
371+
372+ // Smoothly scroll to the top of the page
373+ scrollTopBtn . addEventListener ( 'click' , ( ) => {
374+ window . scrollTo ( {
375+ top : 0 ,
376+ behavior : 'smooth'
377+ } ) ;
378+ } ) ;
379+
380+ // Smoothly scroll to the bottom of the page
381+ scrollBottomBtn . addEventListener ( 'click' , ( ) => {
382+ window . scrollTo ( {
383+ top : document . body . scrollHeight ,
384+ behavior : 'smooth'
385+ } ) ;
386+ } ) ;
387+
388+ // Add a scroll event listener to the window to check button visibility
389+ window . addEventListener ( 'scroll' , handleScrollButtons ) ;
390+
391+ // Initial check when the page loads
392+ handleScrollButtons ( ) ;
341393} ) ;
342394
343395// Add some CSS classes for enhanced animations
0 commit comments