ππ» νλ²κ±° λ©λ΄μ μ¬λΌμ΄λ λ©λ΄λ₯Ό κ²°ν©ν ννμ λ©λ΄μ
λλ€.
This is a menu format that combines a hamburger menu with a slide-out menu.
ππ» νλ²κ±° λ©λ΄λ₯Ό ν΄λ¦νλ©΄ μ¬λΌμ΄λλ©λ΄κ° λνλ©λλ€.
Clicking the hamburger menu reveals a slide-out menu.
ππ» μ¬λΌμ΄λλ©λ΄λ μ°μΈ‘λλ μ’μΈ‘μμ λνλκ² μ€μ ν μ μμ΅λλ€.
The slide menu can be set to appear from either the right or the left side.
ππ» λΆλλ¬μ΄ λ©λ΄μ΄λ¦Ό λ«νμ μν΄μ cssμ tailwindcssλ₯Ό νΌν©ν΄μ μ¬μ©ν©λλ€.
To ensure smooth opening and closing of the menu, a combination of CSS and Tailwind CSS is used.
π λλ ν 리 ꡬ쑰 / Directory structure
tailwindcss-nextjs/
βββ app/
βββ layout.tsx
βββ page.tsx (λ£¨νΈ /)
βββ globals.css
βββ favicon.ico
β
βββ ui/
β βββ page.tsx
β βββ _components/
β βββ button.tsx
β βββ dropdown.tsx
β βββ navigation/
β βββ HorizontalNavMenu.tsx
β βββ MegaMenu.tsx
β βββ Hamburger-Drawer.tsx # hamberger-drawer
β
βββ hamberger-drawer/
β βββ page.tsx # /hamberger-drawer
β βββ game/
β βββ page.tsx # /hamberger-drawer/game
β
βββ button-css/ , button-tailwind/ ... ...
π μ¬λΌμ΄λλ©λ΄μ€μ / Slide Menu Settings
βοΈ μ¬λΌμ΄λλ©λ΄λ₯Ό μ€λ₯Έμͺ½ λλ μΌμͺ½μμ λμ€κ² ν μ μμ΅λλ€.
You can have the slide menu appear from either the right or the left.
1)μ€λ₯Έμͺ½μμ λμ€κ² μ€μ / Set it to appear from the right
... ...
{/** μ€λ₯Έμͺ½μμ λ©λ΄ λμ€λ μ€μ / Setting to make the menu appear from the right */}
<div className={`fixed top-0 right-0 h-full w-[300px] bg-white z-50 shadow-2xl flex flex-col ${open ? 'animate-slide-in' : 'animate-slide-out'}`}>
... ...
<style>{`
/* λ€μ΄κ° λ - μ€λ₯Έμͺ½ / When entering from the right */
@keyframes slide-in {
from { transform: translateX(100%); }
to { transform: translateX(0); }
}
... ...
/* λκ° λ-μ€λ₯Έμͺ½ / When exiting to the right */
@keyframes slide-out {
from { transform: translateX(0); }
to { transform: translateX(100%); }
}
... ...
`}</style>
... ...
2)μΌμͺ½μμ λμ€κ² μ€μ / Set it to appear from the left
... ...
{/* μΌμͺ½μμ λ©λ΄ λμ€λ μ€μ / Setting to make the menu appear from the left */}
<div className={`fixed top-0 left-0 h-full w-[300px] bg-white z-50 shadow-2xl flex flex-col ${open ? 'animate-slide-in' : 'animate-slide-out'}`}>
... ...
<style>{`
... ...
/* λ€μ΄κ° λ - μΌμͺ½ / When entering from the left */
/*@keyframes slide-in {
from { transform: translateX(-100%); }
to { transform: translateX(0); }
}*/
... ...
/* λκ° λ-μΌμͺ½ / When exiting to the left */
/* @keyframes slide-out {
from { transform: translateX(0); }
to { transform: translateX(-100%); }
} */
`}</style>
... ...
3)top-0μ μμμ 0pxλ§νΌ μμΉ ,right-0λ μ€λ₯Έμͺ½μμ 0pxλ§νΌ μμΉ,left-0λ μΌμͺ½μμ 0pxλ§νΌ μμΉ νλλ‘ μ€μ top-0 sets the position to 0px from the top, right-0 sets it to 0px from the right, and left-0 sets it to 0px from the left.
π λ©λ΄ λλλ§ μν / Menu rendering state
... ...
const [render, setRender] = useState(false)
... ...
useEffect(() => {
if (open) {
setRender(true)
document.body.style.overflow = 'hidden'
} else {
// λ©λ΄ λ«μλ , 0.3μ΄ νμ setRenderν¨μ μ€ν
// When closing the menu, execute the `setRender` function after 0.3 seconds.
const t = setTimeout(() => setRender(false), 300)
document.body.style.overflow = ''
return () => clearTimeout(t)
}
}, [open])
... ...
1)λ©λ΄κ° μ΄λ¦¬κ³ λ«νμ λ°λΌ setRenderν¨μλ‘ λ©λ΄ λλλ§ μνλ₯Ό μ²λ¦¬ν©λλ€.
The rendering state of the menu is managed using the setRender function as the menu opens and closes.
2)λ©λ΄κ° μ€ν λμμλλ λ°ν¬λͺ
λ°°κ²½λ€μ νλ©΄ μ€ν¬λ‘€μ μ¨κΉμ²λ¦¬νκ³ λ©λ΄κ° λ«νλ©΄ μ€ν¬λ‘€ μ¬μ©κ°λ₯νκ² μ€μ ν©λλ€.
When the menu is opened, scrolling on the screen behind the semi-transparent background is disabled; when the menu is closed, scrolling is re-enabled.
# λ©λ΄κ° μ΄λ¦ΌμΈ κ²½μ° / When the menu is open
document.body.style.overflow = 'hidden'
# λ©λ΄κ° λ«νμΈ κ²½μ° / When the menu is closed
document.body.style.overflow = ''
π νλ²κ±° λ©λ΄ μ΄λ¦Ό/λ«ν λ²νΌ
Hamburger menu open/close button
... ...
<button onClick={() => setOpen(true)} className="w-11 h-11 bg-black text-white rounded-full">β°</button>
... ...
<button onClick={() => setOpen(false)} className="w-9 h-9 bg-gray-100 rounded-full">β</button>
... ...
π μ¬λΌμ΄λ λ©λ΄ μ΄λ¦Ό/λ«ν
Open/close slide menu
... ...
{render && ( ...
...)}
... ...
π μ€νμΌ /
βοΈ μ¬λΌμ΄λ λ©λ΄ μ¨κΉ,λνλκΈ°
Hide/show slide menu
... ...
from { transform: translateX(100%); } // μμ / start
to { transform: translateX(0); } // λ / end
... ...
1)μ¬λΌμ΄λ λ©λ΄κ° μμ μμΉ λΆν° λ μμΉκΉμ§ μ΄λν©λλ€.
The slide menu moves from the starting position to the end position.
2)100%λ μ¬λΌμ΄λ λ©λ΄μ μ 체 ν¬κΈ°μ
λλ€.
100% is the full size of the slide menu.
3)μ¦ λ©λ΄ μ¨κ²¨μ‘λ€κ° λ©λ΄ μ μ²΄κ° 0pxλ¨μ΄μ§ μμΉλ§νΌ μ΄λνλ μ€μ μ
λλ€.
In other words, this setting involves the menu starting out hidden and then shifting by a distance of 0px.
4)λ©λ΄μ λ°©ν₯μ divμ½λμμ right-0λλ left-0κ° μ΄κΈ° λ©λ΄μ μμΉμ
λλ€. μ΄ λΆλΆμμ λ©λ΄ μ΄λ μ λλ©μ΄μ
μ΄ μμλ©λλ€.
The direction of the menu is determined by the right-0 or left-0 setting in the div code, which defines the initial position of the menu. The animation for the menu’s movement begins from this point.
<div className={`fixed top-0 right-0 h-full w-[300px] ... ...${open ? 'animate-slide-in' : 'animate-slide-out'}`}>
... ...
</div>
βοΈ μ λλ©μ΄μ νν / Animation format
... ...
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
... ...
@keyframes fade-out {
from { opacity: 1; }
to { opacity: 0; }
}
... ...
1)νμ΄λ μΈ(μ²μ²ν λνλ¨),νμ΄λ μμ(μ²μ²ν μ¬λΌμ§) μ€μ μ
λλ€.
These are the settings for fade-in (appearing gradually) and fade-out (disappearing gradually).
2)opacityκ° 0μ΄λ©΄ ν¬λͺ
,1μ΄λ©΄ λΆν¬λͺ
μ΄κ³ 0.5μ΄λ©΄ λ°ν¬λͺ
μ
λλ€.
An opacity value of 0 is transparent, 1 is opaque, and 0.5 is semi-transparent.
... ...
.animate-slide-in { animation: slide-in 0.3s ease-out forwards; }
.animate-slide-out { animation: slide-out 0.3s ease-out forwards; }
.animate-fade-in { animation: fade-in 0.3s ease-out forwards; }
.animate-fade-out { animation: fade-out 0.3s ease-out forwards; }
... ...
1)μ¬λΌμ΄λμΈ,μ¬λΌμ΄λμμ λλ νμ΄λμΈ,νμ΄λμμν λ μΈλΆμ€μ μ
λλ€.
These are the detailed settings for slide-in, slide-out, fade-in, or fade-out effects.
2)0.3sλ μ λλ©μ΄μ
μλ,ease-outμ μ λλ©μ΄μ
ꡬνμ€ μλνν,forwardλ μ λλ©μ΄μ
λλ νμ μνμ
λλ€.
‘0.3s’ is the animation duration, ‘ease-out’ is the speed pattern during the animation, and ‘forwards’ defines the state after the animation has finished.
3)ease-outμ μ²μμ λΉ λ₯΄κ², λμμ μ²μ²ν μ€νλ©λλ€.μ΄ μΈμλ ease-in,ease-in-out,linearλ±μ΄ μμ΅λλ€.
‘ease-out’ starts quickly and slows down toward the end. Other options include ‘ease-in’, ‘ease-in-out’, and ‘linear’.
4)forwardsμ€μ μ΄ μμΌλ©΄ μ λλ©μ΄μ
μ΄ λλν μ²μμΌλ‘ λμκ°λλ€. μ λλ©μ΄μ
μ΄ λλν λ©λ΄κ° μ΄λ¦Όμνλ‘ μ μ§νλ €λ©΄ forwards μ€μ μ΄ μμ΄μΌ ν©λλ€.
If the ‘forwards’ setting is not used, the animation will return to its initial state after it finishes.
To keep the menu in an open state after the animation finishes, you must include the forwards setting.
π ν μ€νΈ / Test
βοΈ PC

βοΈ Mobile

λ§ν볡μ 21μ₯ 22μ / Matthew 21: 22
“λν¬κ° κΈ°λν λμ 무μμ΄λ μ§ λ―Ώκ³ κ΅¬νλ κ²μ λ€ λ°μΌλ¦¬λΌ νμλλΌ”
“And everything you ask in prayer, believing, you will receive.”