Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scroll to top is added #104

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import Loader from "./components/Loader";
import ContactUs from "./pages/ContactUs";
import About from "./pages/About";
import Policy from "./pages/Policy";
import ScrollToTopButton from "./components/ScrollToTopButton";

// import axios from "axios";
// axios.defaults.baseURL = "http://localhost:3001/";

Expand All @@ -26,6 +28,7 @@ function App() {
<RecoilRoot>
<React.Suspense fallback={<Loader/>}>
<Navbar />
<ScrollToTopButton />

<div className="min-h-[80vh] mt-12 pt-12" >
<Routes>
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/components/ScrollToTopButton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* src/ScrollToTopButton.css */
.scroll-to-top {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
}

.scroll-to-top-button {
background-color: #007bff;
border: none;
border-radius: 50%;
color: white;
padding: 10px 20px;
cursor: pointer;
font-size: 20px;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
transition: background-color 0.3s, box-shadow 0.3s;
}

.scroll-to-top-button:hover {
background-color: #0056b3;
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
}
41 changes: 41 additions & 0 deletions frontend/src/components/ScrollToTopButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// src/ScrollToTopButton.tsx
import React, { useState, useEffect } from 'react';
import './ScrollToTopButton.css';

const ScrollToTopButton: React.FC = () => {
const [isVisible, setIsVisible] = useState(false);

const toggleVisibility = () => {
if (window.pageYOffset > 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 (
<div className="scroll-to-top">
{isVisible && (
<button onClick={scrollToTop} className="scroll-to-top-button">
</button>
)}
</div>
);
};

export default ScrollToTopButton;