Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import MindMapEditor from "./pages/MindMapEditor";
import Profile from "./pages/Profile.js";
import SubmitFeedback from "./pages/SubmitFeedback";
import Todo from "./pages/Todo";
import BackToTop from "./components/BackToTop";


const App = () => {
Expand All @@ -26,6 +27,7 @@ const App = () => {
<Router>
<Navbar />
<div style={{ padding: "2rem" }}>
<BackToTop/>
<ScrollToTop />
<Routes>
<Route path="/" element={<Home />} />
Expand Down
59 changes: 59 additions & 0 deletions client/src/components/BackToTop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useState, useEffect } from "react";

function BackToTop() {
const [isVisible, setIsVisible] = useState(false);
// Show button after scrolling
const toggleVisibility = () => {
if (window.scrollY > 300) {
setIsVisible(true);
} else {
setIsVisible(false);
}
};

// Scroll to top smoothly
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};

// Listen for scrolling
useEffect(() => {
window.addEventListener("scroll", toggleVisibility);

// Cleanup
return () => {
window.removeEventListener("scroll", toggleVisibility);
};
}, []);

return (
<>
{isVisible && (
<button
onClick={scrollToTop}
style={{
position: "fixed",
bottom: "20px",
right: "20px",
width: "55px",
height: "55px",
fontSize: "24px",
borderRadius: "50%",
border: "none",
backgroundColor: "#facc15",
color: "black",
cursor: "pointer",
zIndex: 1000,
}}
>
</button>
)}
</>
);
}

export default BackToTop;