Skip to content

Commit

Permalink
Merge pull request #295 from Asymtode712/FloatBtnFeat
Browse files Browse the repository at this point in the history
Added floating button to scroll back to top
  • Loading branch information
hustlerZzZ authored Jun 12, 2024
2 parents d92258e + 864a943 commit 48c0125
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
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

0 comments on commit 48c0125

Please sign in to comment.