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

Added floating button to scroll back to top #295

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
23 changes: 23 additions & 0 deletions src/components/FloatBtn/FloatBtn.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

.scrollButton {
position: fixed;
bottom: 40px;
right: 20px;
background-color: #66BB6A;
color: white;
border: none;
border-radius: 50%;
width: 45px;
height: 45px;
font-size: 24px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
transition: background-color 0.3s ease;
}

.scrollButton:hover {
background-color: #43A047;
}
17 changes: 17 additions & 0 deletions src/components/FloatBtn/FloatBtn.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "./FloatBtn.css";

const FloatBtn = () => {
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
};
return(
<button class="scrollButton" onClick={scrollToTop}>
&#9650;
</button>
);
};

export default FloatBtn;
4 changes: 3 additions & 1 deletion src/pages/About.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Navbar from "../components/Navbar";
import AOS from "aos";
import Loader from "../components/Loader/Loader";
import "aos/dist/aos.css";
import Footer from "../components/Footer"
import Footer from "../components/Footer";
import FloatBtn from "../components/FloatBtn/FloatBtn";

const About = () => {
const [loading,setLoading] = useState(false);
Expand Down Expand Up @@ -198,6 +199,7 @@ const About = () => {
</div>
</div>
<Footer />
<FloatBtn />
</div>
)
}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Navbar from "../components/Navbar";
import CanteenList from "../components/CanteenList";
import Loader from "../components/Loader/Loader";
import Footer from "../components/Footer";
import FloatBtn from "../components/FloatBtn/FloatBtn";

function Home() {

Expand Down Expand Up @@ -56,7 +57,9 @@ function Home() {
<CanteenList canteenData = {canteenData}/>
</div>
<Footer />
<FloatBtn />
</div>

)
}
</>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/News.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Navbar from "../components/Navbar";
import NewsCard from "../components/NewsCard";
import Loader from "../components/Loader/Loader";
import Footer from "../components/Footer";
import FloatBtn from "../components/FloatBtn/FloatBtn";

function News() {
const [articles, setArticles] = useState([]);
Expand Down Expand Up @@ -50,6 +51,7 @@ function News() {
</div>
</main>
<Footer />
<FloatBtn />
</div>
)
}
Expand Down
Loading