From 357d49a3b16679b37bac12c151294cd80393cce5 Mon Sep 17 00:00:00 2001 From: dertyp7 Date: Sun, 14 Jan 2024 18:10:04 +0100 Subject: [PATCH] Add JumpToTop component for mobile devices --- src/App.tsx | 21 ++++++++++++++- src/components/JumpToTop.tsx | 51 ++++++++++++++++++++++++++++++++++++ src/styles/JumpToTop.scss | 11 ++++++++ src/styles/index.scss | 4 +-- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/components/JumpToTop.tsx create mode 100644 src/styles/JumpToTop.scss diff --git a/src/App.tsx b/src/App.tsx index 983dfc3..3e426a7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,15 @@ import Skills from "@sections/Skills"; import Projects from "@sections/Projects"; import SectionLine from "@components/SectionLine"; import Footer from "@components/Footer"; +import JumpToTop from "@components/JumpToTop"; + +function isMobileDevice() { + return ( + /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent + ) || window.innerWidth < 768 + ); +} export default function App() { const aboutRef = useRef(null); @@ -32,6 +41,11 @@ export default function App() { }, []); useEffect(() => { + if (isMobileDevice()) { + // Don't set up the Intersection Observer on small viewports + return; + } + const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { @@ -92,7 +106,12 @@ export default function App() {