Skip to content

Commit

Permalink
Use react-scroll for smooth transition to top
Browse files Browse the repository at this point in the history
  • Loading branch information
tin0312 committed Nov 27, 2023
1 parent 6c57825 commit 4fc06b5
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 117 deletions.
243 changes: 138 additions & 105 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"react-bootstrap": "^2.8.0",
"react-dom": "^18.2.0",
"react-router": "^6.14.2",
"react-router-dom": "^6.14.2"
"react-router-dom": "^6.14.2",
"react-scroll": "^1.9.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand Down
1 change: 1 addition & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
5 changes: 3 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ body {
font-size: 2em !important;
}
.contact-container {
background-color: #151515 !important;
padding-top: 10%;
padding-bottom: 15%;
}
Expand Down Expand Up @@ -311,11 +312,10 @@ body {
font-size: 1.2rem;
}
.project-stacks {
gap: 0.4em;
margin-left: 1em;
}
.project-stacks li{
list-style: none;

}
/* back-to-top button */
.back-to-top {
Expand Down Expand Up @@ -384,6 +384,7 @@ body {
display: flex;
justify-content: space-around;
align-items: center;
background-color: #242424;
margin: 10% auto 18%;
width: 80vw;
}
Expand Down
12 changes: 5 additions & 7 deletions src/Pages/Projects.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react";
import * as Images from "../images";
import { Container, Row, Col } from "react-bootstrap";
import { Link } from 'react-scroll';

export default function Projects() {
const backToTop = document.querySelector(".back-to-top");
const [isBackToTop, setIsBackToTop] = React.useState(false);
Expand Down Expand Up @@ -309,13 +311,9 @@ export default function Projects() {
/>
</Col>
</Row>
<a href="#top" className="back-to-top" title="Back to Top">
<img
src={Images.arrowUp}
alt="Back to Top"
className="back-to-top__image"
/>
</a>
<Link to="top" smooth={true} duration={500} className={`back-to-top ${isBackToTop ? 'visible' : ''}`} offset={-70} title="Back-to-Top">
<img src={Images.arrowUp} alt="Back-to-Top" className="back-to-top__image" />
</Link>
</Container>
);
}
2 changes: 1 addition & 1 deletion src/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Header() {
};

return (
<Container fluid className = "header">
<Container fluid className = "header" id="top">
<Row className = "header-row w-100">
<Col xs={6} lg={6} className="brand-name d-flex align-items-lg-center justify-content-center justify-content-lg-start" to="/">
<div><Link to= "/">Justin</Link></div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Footer from "./Footer"
export default function Layout() {
return (
<div className=" site-wrapper">
<Header />
<Header/>
<main>
<Outlet />
</main>
Expand Down

0 comments on commit 4fc06b5

Please sign in to comment.