Skip to content
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
2 changes: 2 additions & 0 deletions src/components/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import React from 'react'
import Navbar from './Navbar/Navbar'
import Homebox from './Homebox/Homebox'
import Contentbox from './Contentbox/Contentbox'
import ToTopButton from './ToTop/ToTopButton'

function HomePage(props) {
return (
<>
<Navbar />
<Homebox />
<Contentbox />
<ToTopButton />
</>
)
}
Expand Down
32 changes: 32 additions & 0 deletions src/components/ToTop/ToTopButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'
import "./totop.css"
import ArrowUp from "../../images/arrow-up.svg"
import { useState } from 'react'

const ToTopButton = () => {
const [visible, setVisible] = useState(false);

window.addEventListener("scroll", () => {
if (window.scrollY > 50) setVisible(true);
else setVisible(false);
})

try {
document.getElementById('toTopButton').addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: 'smooth',
})
})
} catch (e) {
console.log("Whoops")
}

return (
<div id='toTopButton' className={visible ? "round-button" : "round-button-hidden"}>
<img src={ArrowUp} className='filter-white' />
</div>
)
}

export default ToTopButton
37 changes: 37 additions & 0 deletions src/components/ToTop/totop.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.round-button-hidden {
background-color: dodgerblue;
font-size: 2rem;
border-radius: 50%;
position: fixed;
display: flex;
align-items: center;
justify-content: center;
width: 50px;
height: 50px;
right: 2%;
bottom: 4%;
cursor: pointer;
transition: all 0.2s ease;
transform: scale(0);
}

.round-button {
background-color: dodgerblue;
font-size: 2rem;
border-radius: 50%;
position: fixed;
display: flex;
align-items: center;
justify-content: center;
width: 50px;
height: 50px;
right: 2%;
bottom: 4%;
cursor: pointer;
transition: all 0.2s ease;
}

.round-button:hover {
background-color: rgb(11, 129, 247);
transition: all 0.2s ease;
}
1 change: 1 addition & 0 deletions src/images/arrow-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.