Skip to content

Commit a0c5fae

Browse files
authored
Merge pull request #368 from nisargaa20/scroll-to-bottom-button
scroll bottom button #365
2 parents 8ab1c37 + 0ea98e1 commit a0c5fae

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

src/components/HomePage/header.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,8 @@
316316

317317
.float-animation {
318318
animation: float 2s ease-in-out infinite;
319-
}
319+
}
320+
321+
322+
323+

src/pages/index.module.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,24 @@
3333

3434
.section {
3535
padding: 1rem;
36-
}
36+
}
37+
38+
.scrollToBottomButton {
39+
position: fixed;
40+
bottom: 20px;
41+
right: 20px;
42+
top: auto;
43+
background-color: var(--ifm-color-primary);
44+
color: #fff;
45+
border: none;
46+
border-radius: 50%;
47+
padding: 10px;
48+
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
49+
cursor: pointer;
50+
z-index: 1000;
51+
}
52+
53+
.scrollToBottomButton:hover {
54+
background-color: var(--ifm-color-primary);
55+
box-shadow: 0px 6px 8px rgba(0, 0, 0, 0.2);
56+
}

src/pages/index.tsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import clsx from "clsx";
22
// import Link from "@docusaurus/Link";
3-
import React from "react";
3+
import React, { useState, useEffect } from "react";
44
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
55
import Layout from "@theme/Layout";
66
import Heading from "@theme/Heading";
@@ -12,6 +12,7 @@ import Header from "../components/HomePage/Header";
1212
import Tweet from "../components/Tweet";
1313
import Tweets, { type TweetItem } from "../data/tweets";
1414
import { motion } from "framer-motion";
15+
import { FaArrowDown } from "react-icons/fa";
1516

1617
function TweetsSection(): React.JSX.Element {
1718
const tweetColumns: TweetItem[][] = [[], [], []];
@@ -69,6 +70,29 @@ function TweetsSection(): React.JSX.Element {
6970

7071
export default function Home(): React.JSX.Element {
7172
const { siteConfig } = useDocusaurusContext();
73+
const [showScrollButton, setShowScrollButton] = useState(true);
74+
75+
const scrollToBottom = () => {
76+
window.scrollTo({
77+
top: document.documentElement.scrollHeight,
78+
behavior: "smooth",
79+
});
80+
setShowScrollButton(false);
81+
};
82+
83+
const handleScroll = () => {
84+
if (window.scrollY === 0) {
85+
setShowScrollButton(true);
86+
}
87+
};
88+
89+
useEffect(() => {
90+
window.addEventListener("scroll", handleScroll);
91+
return () => {
92+
window.removeEventListener("scroll", handleScroll);
93+
};
94+
}, []);
95+
7296
return (
7397
<Layout
7498
title={`Hello from ${siteConfig.title}`}
@@ -140,6 +164,15 @@ export default function Home(): React.JSX.Element {
140164
</motion.div>
141165

142166
<TweetsSection />
167+
168+
{showScrollButton && (
169+
<button
170+
onClick={scrollToBottom}
171+
className={styles.scrollToBottomButton}
172+
>
173+
<FaArrowDown />
174+
</button>
175+
)}
143176
</main>
144177
</Layout>
145178
);

0 commit comments

Comments
 (0)