diff --git a/app/components/ScrollUpArrow.tsx b/app/components/ScrollUpArrow.tsx new file mode 100644 index 0000000..f923ad9 --- /dev/null +++ b/app/components/ScrollUpArrow.tsx @@ -0,0 +1,43 @@ +'use client'; +import { useEffect, useState } from 'react'; + +const ScrollToTop = () => { + const [isVisible, setIsVisible] = useState(false); + + const toggleVisibility = () => { + if (window.scrollY > 300) { + setIsVisible(true); + } else { + setIsVisible(false); + } + }; + + const scrollToTop = () => { + window.scrollTo({ + top: 0, + behavior: 'smooth', + }); + }; + + useEffect(() => { + window.addEventListener('scroll', toggleVisibility); + return () => { + window.removeEventListener('scroll', toggleVisibility); + }; + }, []); + + return ( +
+ {isVisible && ( + + )} +
+ ); +}; + +export default ScrollToTop; diff --git a/app/layout.tsx b/app/layout.tsx index fce14c2..632c004 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -4,6 +4,7 @@ import CalendlyScript from './components/CalendlyScript'; import CrispScript from './components/CrispScript'; import Footer from './components/Footer'; import Navbar from './components/Navbar'; +import ScrollToTop from './components/ScrollUpArrow'; import Tracking from './Tracking'; export const metadata: Metadata = { @@ -42,6 +43,7 @@ export default function RootLayout({ {children}