Skip to content
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

Feature/scrool to top #95

Open
wants to merge 3 commits 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
136 changes: 131 additions & 5 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.26.1",
"styled-components": "^6.1.13",
"three": "^0.168.0"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import FAQPage from './pages/FAQPage'
import Navbar from './components/Navbar'
import CreateNFT from './pages/CreateNFTPage'
import NotFoundPage from './components/NotFoundPage'
import ScrollToTop from './components/ScrollToTop'
function App() {
const [wallet, setWallet] = useState(null)
useEffect(() => {
Expand Down Expand Up @@ -46,6 +47,7 @@ function App() {
</Routes>
</div>
</div>
<ScrollToTop></ScrollToTop>
</BrowserRouter>
)
}
Expand Down
43 changes: 43 additions & 0 deletions frontend/src/components/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useState, useEffect } from 'react'

const ScrollToTop = () => {
const [isVisible, setIsVisible] = useState(false)

// Toggle visibility based on scroll position
const toggleVisibility = () => {
if (window.pageYOffset > 150) {
setIsVisible(true)
} else {
setIsVisible(false)
}
}

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

// Add event listener for scroll changes
useEffect(() => {
window.addEventListener('scroll', toggleVisibility)
return () => window.removeEventListener('scroll', toggleVisibility)
}, [])

return (
<div>
{isVisible && (
<button
onClick={scrollToTop}
className="fixed bottom-7 right-3 w-12 h-12 bg-customPurple text-white rounded-full shadow-md hover:shadow-lg hover:scale-105 transition duration-300 flex items-center justify-center"
>
<span className="text-4xl font-bold text-black">↑</span>
</button>
)}
</div>
)
}

export default ScrollToTop
17 changes: 9 additions & 8 deletions frontend/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {
colors: {
customPurple: 'rgba(219, 118, 247, 1)',
},
},
},
plugins: [],
}
Loading