-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a4b9d6
commit 2b7e667
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Image from 'next/image'; | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
const TopButton = () => { | ||
const [showButton, setShowButton] = useState(false); | ||
|
||
const scrollToTop = () => { | ||
window.scroll({ | ||
top: 0, | ||
behavior: 'smooth', | ||
}); | ||
}; | ||
useEffect(() => { | ||
const ShowButtonClick = () => { | ||
if (window.scrollY > 500) { | ||
setShowButton(true); | ||
} else { | ||
setShowButton(false); | ||
} | ||
}; | ||
window.addEventListener('scroll', ShowButtonClick); | ||
return () => { | ||
window.removeEventListener('scroll', ShowButtonClick); | ||
}; | ||
}, []); | ||
return ( | ||
<> | ||
{showButton && ( | ||
<div className="fixed right-[30px] bottom-[30px] z-30"> | ||
<button | ||
onClick={scrollToTop} | ||
type="button" | ||
className="flex justify-center items-center w-[40px] h-[40px] rounded-full bg-nomad-black border-[3px] border-solid border-var-gray1 dark:bg-var-dark2 dark:border-var-dark3" | ||
> | ||
<Image | ||
src="/icon/chevron_up_white.png" | ||
alt="화살표" | ||
width={26} | ||
height={26} | ||
/> | ||
</button> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default TopButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.