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() {
-
+
+ {isMobileDevice() ? (
+
+ ) : (
+
+ )}
);
}
diff --git a/src/components/JumpToTop.tsx b/src/components/JumpToTop.tsx
new file mode 100644
index 0000000..3c9d2cc
--- /dev/null
+++ b/src/components/JumpToTop.tsx
@@ -0,0 +1,51 @@
+import { useState, useEffect } from "react";
+import "@styles/JumpToTop.scss"; // Assuming you have a CSS file for styling
+
+export default function JumpToTop() {
+ const [isVisible, setIsVisible] = useState(false);
+
+ // Show button when page is scrolled upto given distance
+ const toggleVisibility = () => {
+ if (window.scrollY > 50) {
+ setIsVisible(true);
+ } else {
+ setIsVisible(false);
+ }
+ };
+
+ // Set the top coordinate to 0
+ // make scrolling smooth
+ const scrollToTop = () => {
+ window.scrollTo({
+ top: 0,
+ });
+ };
+
+ useEffect(() => {
+ window.addEventListener("scroll", toggleVisibility);
+ return () => window.removeEventListener("scroll", toggleVisibility);
+ }, []);
+
+ return (
+
+ {isVisible && (
+
+ )}
+
+ );
+}
diff --git a/src/styles/JumpToTop.scss b/src/styles/JumpToTop.scss
new file mode 100644
index 0000000..e6b7d9d
--- /dev/null
+++ b/src/styles/JumpToTop.scss
@@ -0,0 +1,11 @@
+.jumpToTop {
+ position: fixed;
+ bottom: 20px;
+ right: 20px;
+ cursor: pointer;
+
+ svg {
+ width: 50px;
+ height: 50px;
+ }
+}
diff --git a/src/styles/index.scss b/src/styles/index.scss
index 39f332d..4a08371 100644
--- a/src/styles/index.scss
+++ b/src/styles/index.scss
@@ -27,9 +27,7 @@
}
html {
- @media (min-width: 768px) {
- scroll-behavior: smooth;
- }
+ scroll-behavior: smooth;
}
h1 {