์ปดํจํฐ๊ฐ ์ฝ๋๋ฅผ ์ฝ๋ ์์๋ฅผ ์ดํดํ๊ณ ์ ์ฉํด๋ณด๊ธฐ
๐ ์ฝ๋๋ ํญ์ ์์์ ์๋๋ก ์ฝ๋๋ค
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์๋์ ์๋ ์ฝ๋๊ฐ 1์์๋ก ์ ์ฉ๋๋ค. (์ฝ๊ธฐ๋ ์์์ ์๋ / ์ ์ฉ์ ์๋์์ ์)
Position fixed๋ฅผ ํ ์ฝ๋์ position:relative๋ฅผ ์ฃผ์ง ์๊ณ absolute๋ฅผ ์ค ์ฝ๋๊ฐ ์์ผ๋ฉด ์ ์ฉ ์์๋ ์๋์์ ์๋ก ์ ์ฉ๋๋ ๊ฒ์ด๋ค.
Absolute๋ฅผ ์ด์ฉํ์ฌ ๋ชจ๋ ํ๋ฉด์ ๋ฎ๋ div๋ฅผ ๋ง๋ ๋ค๊ณ ์น์
๊ทธ๋ ๋ค๋ฉด div๊ฐ ๋งจ ์๋์ ์์นํด์ผ ๋ชจ๋ ํ๋ฉด์ ๋ฎ์ ์ ์๋ค.
์ฝ๋๋ฅผ ์์ฑํ ๋ ํญ์ ์ฝ๋ ์์๋ฅผ ์๊ฐํ์ฌ ์ ์ฉ๋๋ ์์๋ฅผ ๊ณ์ฐํด์ผ ๋๋ค.
๐ ์ ์ฉํ๊ธฐ!
ํ๋ฉด์ ๊ฐ๋ ธ๋ค๊ฐ ๋ํ๋๋ ์ ๋๋ฉ์ด์ ์ ๋ง๋ค์ด๋ณด์!
1. ๋จผ์ ํ๋ฉด์ ๊ฐ๋ฆฌ๋ div์์ฑ๊ฐ์ ์ฃผ์
#splash-screen {
background-color: var(--yellow);
position: absolute;
height: 100vh;
width: 100vw;
top: 0;
display: flex;
justify-content: center;
align-items: center;
font-size: 150px;
}
2. ๊ทธ ๋ค์ ํคํ๋ ์์ผ๋ก ์์ฉ์์๋ฅผ ๋ง๋ค๊ณ
@keyframes hideSplashScreen {
Form {
opacity: 1;
}
to {
opacity: 0;
}
}
๊ผญ form to ๊ฐ ์๋๋๋ผ๋ 0% 50% 100% ์ด๋ ๊ฒ ๋๋ ์ ๋ ์๋ค.
3. Animation์ ์ถ๊ฐํ์ฌ ์์ฉํ๊ฒํ์
#splash-screen {
background-color: var(--yellow);
position: absolute;
height: 100vh;
width: 100vw;
top: 0;
display: flex;
justify-content: center;
align-items: center;
font-size: 150px;
animation: hideSplashScreen 1s ease-in-out;
}
์ด๋ ๊ฒํ๋ฉด ์ ๋๋ฉ์ด์ ์ ํ๋ฉด์ ๋ณด์ฌ์ฃผ์๋ค๊ฐ ๋ค์ ์ฒ์์ํ๋ก ๋์๊ฐ ํ๋ฉด์ ๊ฐ๋ฆด ๊ฒ์ด๋ค.
animation: hideSplashScreen 1s ease-in-out forwards;
์ด๋ forwards๋ฅผ ์ถ๊ฐํ๋ฉด final property value(๋ง์ง๋ง ์์ฑ ๊ฐ)์ ์ ์งํ๊ฒ ํ์ฌ ์ ๋๋ฉ์ด์ ์ด ๋๋๊ณ ์ ์งํ๋ค.
๊ทธ๋์ ํ๋ฉด์ด ๋ณด์ผ ์ ์๊ฒ ์ง๋ง ์ฌ์ ํ element(splash-screen)๋ ๋จ์์์ด์ ํด๋ฆญ์ด ๋ถ๊ฐ๋ฅํ๋ค.
๊ทธ๋์ ๋ช ๊ฐ์ง ์์ฑ(property)์ ์๋ํด๋ณผ ์ ์๋๋ฐ
๊ทธ ์ค visibility: hidden; ๋ ๋ง์ฐ์ค์ ๊ฑธ๋ฆฌ์ง ์๊ฒ ๋น ์ ธ๋ฒ๋ฆฌ๊ฒ ํ๋ค.
ํ์ง๋ง ๋ธ๋ผ์ฐ์ ๊ฒ์ฌ๋ฅผ ํตํด์ ๋ณด๋ฉด element๋ ์์ง ์กด์ฌํ๊ณ ์๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ฐ๋ฆฌ๋ javascript๋ฅผ ์ด์ฉํด์ผ ํ๋ค.
Javascript๋ “๋”์ ์ญํ ์ด๊ธฐ ๋๋ฌธ์ด๋ค.
๐ ์ ๋๋ฉ์ด์ ์ ์ง์ฐ์ํค๋ ๋ฐฉ๋ฒ
animation-delay: 5s;
๐ ์ ๋ฆฌํ๊ธฐ!
1. ์ ๋๋ฉ์ด์ ์ ๋ง์ง๋ง ๊ฐ์ ๊ธฐ์ตํ๊ณ ์ถ๋ค๋ฉด forwards
2. ์ ๋๋ฉ์ด์ ์ ๋ฐ๋ณตํ๊ณ ์ถ์ผ๋ฉด infinite
3. ์ ๋๋ฉ์ด์ ์์ ์ ๋ชจ์ต์ ์จ๊ธฐ๊ณ ์ถ์ผ๋ฉด keyframes์ด ์๋ element์๊ฒ๋ translate์ opacity์๊ฒ ๊ฐ์ ์ค์ผํ๋ค.
๐ translate ๋ณต์ตํ๊ธฐ
translate() - CSS: Cascading Style Sheets | MDN
The translate() CSS function repositions an element in the horizontal and/or vertical directions. Its result is a <transform-function> data type.
developer.mozilla.org