Skip to content
Merged
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 frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ApplicationFormPage from './pages/ApplicationFormPage/ApplicationFormPage
import ApplicantsTab from './pages/AdminPage/tabs/ApplicantsTab/ApplicantsTab';
import ApplicantDetailPage from './pages/AdminPage/tabs/ApplicantsTab/ApplicantDetailPage/ApplicantDetailPage';
import ClubUnionPage from './pages/ClubUnionPage/ClubUnionPage';
import { ScrollToTopButton } from '@/components/common/ScrollToTopButton/ScrollToTopButton';
import 'swiper/css';

const queryClient = new QueryClient();
Expand All @@ -29,6 +30,7 @@ const App = () => {
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<GlobalStyles />
<ScrollToTopButton />
<Routes>
<Route
path='/'
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/assets/images/icons/scroll_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import styled from 'styled-components';

export const ScrollButton = styled.button<{ $isVisible: boolean }>`
position: fixed;
bottom: 80px;
right: 30px;
z-index: 1000;
opacity: ${({ $isVisible }) => ($isVisible ? 1 : 0)};
visibility: ${({ $isVisible }) => ($isVisible ? 'visible' : 'hidden')};
transition: opacity 0.3s, visibility 0.3s;
background: none;
border: none;
cursor: pointer;
padding: 0;

img {
width: 50px;
height: 50px;
display: block;
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useScrollTrigger } from '@/hooks/useScrollTrigger';
import scrollButtonIcon from '@/assets/images/icons/scroll_icon.svg';
import * as Styled from './ScrollToTopButton.styles';


export const ScrollToTopButton = () => {
const { isTriggered } = useScrollTrigger();

const handleScrollToTop = () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
};

return (
<Styled.ScrollButton
type="button"
$isVisible={isTriggered}
onClick={handleScrollToTop}
aria-label="위로 이동하기"
>
<img src={scrollButtonIcon} alt="Scroll to top" />
</Styled.ScrollButton>
);
};
39 changes: 39 additions & 0 deletions frontend/src/hooks/useScrollTrigger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useEffect, useState, useCallback } from "react";

interface ScrollTriggerOptions {
threshold?: number;
direction?: 'up' | 'down';
passive?: boolean;
onChange?: (next: boolean) => void;
}


export const useScrollTrigger = ({
threshold = 10,
direction = 'down',
passive = true,
onChange,
}: ScrollTriggerOptions = {}) => {
const [isTriggered, setIsTriggered] = useState(false);

const handleScroll = useCallback(() => {
const scrollY = window.scrollY;
const shouldShowButton =
direction === 'down'
? scrollY > threshold
: scrollY < threshold;

setIsTriggered((prev) => {
if (shouldShowButton === prev) return prev;
onChange?.(shouldShowButton);
return shouldShowButton;
})
}, [ direction, threshold, onChange]);

useEffect(() => {
window.addEventListener('scroll', handleScroll, { passive });
return () => window.removeEventListener('scroll', handleScroll);
}, [handleScroll, passive]);

return { isTriggered };
};