-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #252 from FinalDoubleTen/TripsQA/Design
ScrollTopButton / 여행페이지 Nav 추가
- Loading branch information
Showing
10 changed files
with
62 additions
and
6 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
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,42 @@ | ||
import { TopIcon } from '@components/common/icons/Icons'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
const ScrollTopButton = () => { | ||
const [visible, setVisible] = useState<boolean>(false); | ||
|
||
const checkScrollTop = () => { | ||
if (!visible && window.scrollY > 300) { | ||
setVisible(true); | ||
} else if (visible && window.scrollY <= 300) { | ||
setVisible(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener('scroll', checkScrollTop); | ||
return () => { | ||
window.removeEventListener('scroll', checkScrollTop); | ||
}; | ||
}, [visible]); | ||
|
||
const scrollToTop = () => { | ||
window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
}; | ||
|
||
if (!visible) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
className="sticky bottom-[20px] | ||
mt-[-50px] flex h-12 w-12 cursor-pointer items-center justify-center rounded-full bg-white shadow-md" | ||
style={{ left: 'calc(100%)' }}> | ||
<button onClick={scrollToTop}> | ||
<TopIcon /> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ScrollTopButton; |
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
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
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
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
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
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
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
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