728x90
๋ฐ์ํ
๐ก ์ค์ต ํฌ์ธํธ!
- ๋ก๊ทธ์ธ ๋ฒํผ์ ๋๋ฅด๋ฉด ์์ด๋์ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ฃ์ ์ ์๋ ๋ชจ๋ฌ์ฐฝ์ด ์์ํ ๋จ๊ณ ๋ซ๊ธฐ ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ชจ๋ฌ์ฐฝ์ด ์์ํ ์ฌ๋ผ์ง๊ฒ ํ๋ค.
๐ HTML
<div class="black-bg">
<div class="white-bg">
<h4>๋ก๊ทธ์ธํ์ธ์</h4>
<form action="success.html">
<div class="my-3">
<input type="text" class="form-control" id="email">
</div>
<div class="my-3">
<input type="password" class="form-control" id="password">
</div>
<button type="submit" class="btn btn-primary" id="submit">์ ์ก</button>
<button type="button" class="btn btn-danger" id="close">๋ซ๊ธฐ</button>
</form>
</div>
</div>
<button class="btn-login">๋ก๊ทธ์ธ</button>
- ๋จผ์ ๋ก๊ทธ์ธ ๋ฒํผ๊ณผ ๋ก๊ทธ์ธ ๋ฒํผ์ ๋๋ ์ ๋ ๋ฐ ๋ชจ๋ฌ์ฐฝ ๊ธฐ๋ณธ ๋ ์ด์์์ ๋ง๋ค์ด์ค๋ค.
- ๋ชจ๋ฌ์ฐฝ์ ํ๋ฉด ์ ์ฒด๋ฅผ ๋ฎ์ด์ผ ํ๋ฏ๋ก body ํ๊ทธ ์ค ์ ์ผ ์๋จ์ ๋ชจ๋ฌ์ฐฝ ๊ด๋ จ html ์ด ์์นํด์ผ ํ๋ค.
๐ CSS
.black-bg {
width: 100%;
height: 100%;
position: fixed;
background: rgba(0, 0, 0, 0.6);
z-index: 5;
padding: 30px;
visibility: hidden; /* ์ ๋๋ฉ์ด์
์ค ๋ display: none ๋์ฉ, ์์ ๋ ๊ฒ ์๋๋ผ ๋ชจ์ต๋ง ์จ๊น */
opacity: 0;
transition: all 0.5s;
}
.white-bg {
background: white;
border-radius: 5px;
padding: 30px;
}
.btn-login {
background: gold;
border: none;
margin: 10px;
padding: 8px 24px;
border-radius: 5px;
}
.show {
display: block; // ์ด ๋ถ๋ถ์ Navbar ๋ฅผ ์ํ ์์ฑ
opacity: 1;
visibility: visible;
}
- ๋จผ์ ๋ฐํฌ๋ช ์ธ ๊ฒ์ ๋ชจ๋ฌ์ฐฝ ๋ฐฐ๊ฒฝ์ ๋ง๋ค๊ณ z-index ๊ฐ์ ๋ฃ์ด ํ๋ฉด์ ๋ฎ์ ์ ์๋๋ก ํ๋ค.
- z-index ๋ position: static (๊ธฐ๋ณธ)์ธ ๊ฒฝ์ฐ์๋ ์ฌ์ฉํ ์ ์์ผ๋ฏ๋ก ์ฃผ์!
- ๋ชจ๋ฌ์ฐฝ์ด ๋ฟ !ํ๊ณ ๋จ๋ ๊ฒ ์๋๋ผ ์์ํ ๋จ๊ณ , ๋ซํ ๋๋ ์์ํ ๋ซํ๊ฒ ํ๊ธฐ ์ํด transition ์ ์ฌ์ฉํ ๊ฒ์ด๋ค.
- ์ด ๋ ์ฃผ์ํ ์ ์ ์ด ๋๊น์ง ํ๋ฉด์ ์๋ณด์ด๊ฒ ํ๊ธฐ ์ํด์๋ display: none ์ ์ฌ์ฉํ๋๋ฐ ์ด ์์ฑ์ ์ด์ฉํ๋ฉด transition ๊ณผ ๊ฐ์ ์ ๋๋ฉ์ด์ ํจ๊ณผ๊ฐ ์ ์ฉ์ด ์ ์ ๋๋ค๊ณ ํ๋ค. ๊ทธ๋์ ๋์ ์ฌ์ฉํ๋ ๊ฒ์ด visibility : hidden !
- show ๋ผ๋ ํด๋์ค๊ฐ ๋ถ์์ ๋ visibility: visible ์ด ์ ์ฉ๋๊ณ , transition ์์ฑ์ ํตํด 0.5์ด ๋์ ์ด๊ธฐ๊ฐ์ด์๋ opacity: 0 ์ด opacity: 1 ์ด ๋๋ฉด์ ์์ํ ๋ชจ๋ฌ์ฐฝ์ด ๋ณด์ด๊ฒ ๋๋ค.
๐ JavaScript
$('.btn-login').eq(0).on('click', function(){
$('.black-bg').eq(0).toggleClass('show');
})
$('#close').eq(0).on('click', function(){
$('.black-bg').eq(0).toggleClass('show');
})
- ๋ก๊ทธ์ธ ๋ฒํผ์ ๋๋ ์ ๋, ๋ซ๊ธฐ ๋ฒํผ์ ๋๋ ์ ๋ show ํด๋์ค๊ฐ ๋ถ์๋ค ๋จ์ด์ก๋คํ๋ฉด์ ๋ชจ๋ฌ์ฐฝ์ด ๋ณด์๋ค๊ฐ ์ ๋ณด์๋ค๊ฐ ํ ์ ์๊ฒ toggleClass ๋ฅผ ํ์ฉํ์ฌ ๊ธฐ๋ฅ์ ๋ฃ์๋ค.
- id ๋ฅผ ๋ถ๋ฌ์ค๋ ๊ฒฝ์ฐ eq(์ซ์)์ ๊ฐ์ด ์ธ๋ฑ์ค๋ฅผ ๋ฃ์ด์ค ํ์๋ ์์ง๋ง ๋ฃ์ด๋ ์๊ด์ ์์ด์ ๋ฃ์๋ค.
(์ฌ์ค ๋ฃ๋ ์ต๊ด์ด ์๊ฒจ๋ฒ๋ ค์...)
728x90
๋ฐ์ํ