Skip to content

feat: Scroll on Top Button Added #1927

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
MONGODB_URI=

GITHUB_CLIENT_SECRET=
GITHUB_CLIENT_ID=

Expand Down
3 changes: 3 additions & 0 deletions components/UI/Contact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import axios from "axios";
import { useState } from "react";
import NewTwitterLogo from "./NewTwitterlogo";
import { RiYoutubeFill, RiGithubFill, RiTwitterFill, RiLinkedinFill } from "react-icons/ri";
import ScrollToTop from "./ScrollToTop";
const Contact = () => {
const [submitted, setSubmitted] = useState(false);
const handleSubmit = async (event) => {
Expand Down Expand Up @@ -139,7 +140,9 @@ const Contact = () => {
</form>
</>
)}

</Col>
<ScrollToTop />
</Row>
</Container>
{/* <Container className=" w-80">
Expand Down
59 changes: 59 additions & 0 deletions components/UI/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useState, useEffect } from 'react';
const ScrollToTop = () => {
const [isVisible, setIsVisible] = useState(false);

// Show button when page is scrolled down by 300px
const toggleVisibility = () => {
if (window.pageYOffset > 300) {
setIsVisible(true);
} else {
setIsVisible(false);
}
};

// Scroll the window to the top smoothly
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
};

useEffect(() => {
window.addEventListener('scroll', toggleVisibility);
return () => {
window.removeEventListener('scroll', toggleVisibility);
};
}, []);

return (
<>
{isVisible && (
<button
onClick={scrollToTop}
style={{
position: 'fixed',
bottom: '40px',
right: '40px',
padding: '10px 15px',
fontSize: '18px',
borderRadius: '50%',
border: 'none',
backgroundColor: '#0070f3',
color: '#fff',
cursor: 'pointer',
boxShadow: '0 2px 5px rgba(0,0,0,0.3)',
zIndex: 1000,
width:'50px'
}}
aria-label="Scroll to top"
title="Scroll to top"
>
</button>
)}
</>
);
};

export default ScrollToTop;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"react-dom": "18.2.0",
"react-icons": "^4.9.0",
"react-loader-spinner": "^5.3.4",
"react-scroll": "^1.9.3",
"react-slick": "^0.29.0",
"react-terminal": "^1.3.0",
"reactstrap": "^9.1.1",
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2812,6 +2812,11 @@ lodash.merge@^4.6.2:
resolved "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

lodash.throttle@^4.1.1:
version "4.1.1"
resolved "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz"
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==

lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
Expand Down Expand Up @@ -3328,6 +3333,14 @@ react-popper@^2.2.4:
react-fast-compare "^3.0.1"
warning "^4.0.2"

react-scroll@^1.9.3:
version "1.9.3"
resolved "https://registry.npmjs.org/react-scroll/-/react-scroll-1.9.3.tgz"
integrity sha512-xv7FXqF3k63aSLNu4/NjFvRNI0ge7DmmmsbeGarP7LZVAlJMSjUuW3dTtLxp1Afijyv0lS2qwC0GiFHvx1KBHQ==
dependencies:
lodash.throttle "^4.1.1"
prop-types "^15.7.2"

react-slick@^0.29.0:
version "0.29.0"
resolved "https://registry.npmjs.org/react-slick/-/react-slick-0.29.0.tgz"
Expand Down
Loading