diff --git a/client/package.json b/client/package.json index 8eac4a4..61c23a3 100644 --- a/client/package.json +++ b/client/package.json @@ -10,6 +10,7 @@ "preview": "vite preview" }, "dependencies": { + "@fortawesome/fontawesome-free": "^6.6.0", "@reduxjs/toolkit": "^1.9.6", "axios": "^1.6.2", "hamburger-react": "^2.5.0", @@ -21,6 +22,7 @@ "react-razorpay": "^2.0.1", "react-redux": "^8.1.2", "react-router-dom": "^6.16.0", + "react-scroll": "^1.9.0", "redux-persist": "^6.0.0" }, "devDependencies": { diff --git a/client/src/components/BackToTop/BackToTop.jsx b/client/src/components/BackToTop/BackToTop.jsx new file mode 100644 index 0000000..30c0a2a --- /dev/null +++ b/client/src/components/BackToTop/BackToTop.jsx @@ -0,0 +1,45 @@ +import React, { useState, useEffect } from "react"; +import { animateScroll } from 'react-scroll'; +import '@fortawesome/fontawesome-free/css/all.min.css'; + +const BackToTop = () => { + const [showButton, setShowButton] = useState(false); + + useEffect(() => { + const handleScroll = () => { + if (window.scrollY > 90) { + setShowButton(true); + } else { + setShowButton(false); + } + }; + + window.addEventListener("scroll", handleScroll); + + return () => { + window.removeEventListener("scroll", handleScroll); + }; + }, []); + + const handleClick = () => { + animateScroll.scrollToTop({ + top: 0, + behavior: "smooth", + duration: 200 + }); + }; + + return ( + <> + + + ); +}; + +export default BackToTop; diff --git a/client/src/components/layout.jsx b/client/src/components/layout.jsx index 6281efc..fbcf5d2 100644 --- a/client/src/components/layout.jsx +++ b/client/src/components/layout.jsx @@ -3,6 +3,7 @@ import Navbar from "./Navbar/navbar"; import { Outlet } from "react-router-dom"; import Footer from "./Footer"; import Preloader from "./Preloader/Preloader"; +import BackToTop from "./BackToTop/BackToTop"; const Layout = () => { return ( @@ -13,6 +14,7 @@ const Layout = () => {