This repository was archived by the owner on Sep 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +145
-35
lines changed
Expand file tree Collapse file tree 4 files changed +145
-35
lines changed Original file line number Diff line number Diff line change 1212 "dependencies" : {
1313 "@fortawesome/fontawesome-svg-core" : " ^6.4.2" ,
1414 "@fortawesome/free-brands-svg-icons" : " ^6.4.2" ,
15+ "@fortawesome/free-solid-svg-icons" : " ^6.5.1" ,
1516 "@fortawesome/react-fontawesome" : " ^0.2.0" ,
1617 "@headlessui/react" : " ^1.7.17" ,
1718 "@headlessui/tailwindcss" : " ^0.2.0" ,
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { PrimaryFeatures } from '@/components/PrimaryFeatures'
88import { SecondaryFeatures } from '@/components/SecondaryFeatures'
99import { Testimonials } from '@/components/Testimonials'
1010import { Founders } from '@/components/Founders'
11+ import { ScrollToTop } from '@/components/ScrollToTop'
1112
1213export default function Home ( ) {
1314 return (
@@ -24,6 +25,7 @@ export default function Home() {
2425 < Faqs />
2526 </ main >
2627 < Footer />
28+ < ScrollToTop />
2729 </ >
2830 )
2931}
Original file line number Diff line number Diff line change 1+ 'use client' ;
2+ import { Button } from "./Button" ;
3+ import { useState , useEffect } from "react"
4+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
5+ import { faArrowUp } from "@fortawesome/free-solid-svg-icons" ;
6+ export function ScrollToTop ( ) {
7+ const [ isVisible , setIsVisible ] = useState ( false )
8+
9+ const toggleVisibility = ( ) => {
10+ if ( window . scrollY > 300 ) {
11+ setIsVisible ( true )
12+ }
13+ else {
14+ setIsVisible ( false )
15+ }
16+ }
17+ const scrollToTop = ( ) => {
18+ window . scrollTo ( {
19+ top :0 ,
20+ behavior :"smooth" ,
21+ } )
22+ }
23+
24+ useEffect ( ( ) => {
25+ window . addEventListener ( "scroll" , toggleVisibility )
26+ return ( ) => {
27+ window . removeEventListener ( "scroll" , toggleVisibility )
28+ }
29+ } , [ ] )
30+ return (
31+ < div className = "fixed bottom-2 right-2" >
32+ < Button className = { isVisible ? 'opacity-100' : 'opacity-0' } variant = { "solid" } onClick = { ( ) => scrollToTop ( ) } >
33+ < FontAwesomeIcon icon = { faArrowUp } color = "white" size = "xl" className = "h-6 w-6" aria-hidden = "true" />
34+ </ Button >
35+ </ div >
36+ )
37+
38+ }
You can’t perform that action at this time.
0 commit comments