๐Ÿ“’TIL) Sunstagram ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€ ๊ตฌํ˜„

TaeYangยท2021๋…„ 9์›” 16์ผ
2

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
6/8
post-thumbnail

์˜ˆ์ „ ๋ฒ„์ „์ธ ์ธ์Šคํƒ€๊ทธ๋žจ ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€๋ฅผ ์•ฝ๊ฐ„์˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ๋„ฃ์–ด์„œ ๋กœ๊ทธ์ธ ํ• ์ˆ˜ ์žˆ๊ฒŒ ๊ตฌํ˜„ํ•ด๋ดค์Šต๋‹ˆ๋‹ค.
๋ถ€์กฑํ•˜์ง€๋งŒ ์ฝ”๋“œ๋“ค์„ ๋ณด๋ฉด์„œ ๋ถ„์„์•„๋‹Œ ๋ถ„์„๊ณผ ์ƒ๊ฐ๋“ค์„ ์ ์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


๊ธฐ์ˆ 

  • HTML
  • CSS
  • JavaScript

๊ตฌํ˜„์‚ฌํ™ฉ

  • ์˜ˆ์ „ ์ธ์Šคํƒ€๊ทธ๋žจ ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€ ๊ตฌํ˜„
  • ๋กœ๊ทธ์ธ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ -> ์•„์ด๋”” @ ํฌํ•จ ๋น„๋ฐ€๋ฒˆํ˜ธ 5์ž๋ฆฌ ์ด์ƒ ์ผ๋•Œ ๋กœ๊ทธ์ธ๋ฒ„ํŠผ ํ™œ์„ฑํ™” ๋ฐ ๋ฒ„ํŠผ ์ƒ‰ ๋ณ€๊ฒฝ

HTML ์ฝ”๋“œ

<main class="main-box">
    <div class ="container">
      <span class="logo-text">Sunstagram</span>
      <input type="text" id="id-email" placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" />
      <input type="password" id="password" placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" />
      <button type="button" onclick="location.href='main.html'" class="button button-off" id="login-button" disabled>๋กœ๊ทธ์ธ</button>
      <div class="validity">์•„์ด๋”” ๋˜๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ž˜๋ชป ์ž…๋ ฅ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.</div>
      <a href="">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a>
    </div>
  </main>

HTML์ฝ”๋“œ๋งŒ ์ž‘์„ฑํ•˜๋ฉด ์œ„์— ์‚ฌ์ง„์ฒ˜๋Ÿผ ๋งŒ๋“ค์–ด ์ง‘๋‹ˆ๋‹ค.
์•„๋ž˜์— ์–ด๋–ค ์ˆœ์„œ๋กœ ์ฝ”๋“œ๋“ค์„ ์ ์—ˆ๋Š”์ง€ ๋ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

  • CSS๋ฅผ ํŽธํ•˜๊ฒŒ ์ ์šฉํ• ์ˆ˜ ์žˆ๋„๋ก ๋ชจ๋“  ํƒœ๊ทธ๋“ค์„ div๋กœ ๋ฌถ์–ด์คฌ์Šต๋‹ˆ๋‹ค.
  • ๋ชจ๋“  ํƒœ๊ทธ๋ฅผ ๋ฌถ์€div์— Flex ๋ฅผ ์ค˜์„œ ์„ธ๋กœ๋กœ ์ •๋ ฌ ํ•œ๋‹ค ์ƒ๊ฐํ•˜๊ณ  ํƒœ๊ทธ๋“ค์„ ์ˆœ์„œ๋Œ€๋กœ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

CSS ์ฝ”๋“œ

.main-box{
  display: flex;
  justify-content: center;
  margin-top: 6%;
}

.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 350px;
  height: 380px;
  background-color: rgb(255, 255, 255);
  border: 1px solid rgb(219, 219, 219);
}

.logo-text {
  margin-top: -70px;
  margin-bottom: 40px;
  font-family: 'Lobster', cursive;
  font-size: 42px;
  font-weight:bolder;
}

input {
  width: 270px;
  height: 37px;
  margin-bottom: 7px;
  padding-left: 8px;
  color: rgb(142, 142, 142);
  outline-style: none;
  border: 1px solid rgb(219, 219, 219);
  border-radius: 4px;
  background-color: rgb(250, 250, 250);
  font-size: 12px;
}

.button {
  width: 270px;
  height: 30px;
  margin: 7px 0px;
  color: white;
  background-color: #0095f6;
  border: 0px solid;
  border-radius: 5px;
}

.button-off {
  background-color: #b9dffc;
  cursor: not-allowed;
}

.container>div {
  font-size: 13px;
  font-weight: 400;
}

.validity {
  display: none;
}


a {
  position: relative;
  bottom: -80px;
  font-size: 12px;
  text-decoration: none;
}


์œ„ ์‚ฌ์ง„์€ HTML๊ณผ CSS๋งŒ ์ ์šฉ ์‹œํ‚จ ํ™”๋ฉด์ž…๋‹ˆ๋‹ค

ํŽธํ•˜๊ฒŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ display : flex ๋ฅผ ์‚ฌ์šฉํ• ๋ ค๊ณ  ๋…ธ๋ ฅ์„ ๋งŽ์ด ํ–ˆ์Šต๋‹ˆ๋‹ค.
main-box์— flex justify-content: center๋ฅผ ์ค˜์„œ ๊ฐ€์šด๋ฐ๋กœ ์ •๋ ฌ ์‹œ์ผฐ์Šต๋‹ˆ๋‹ค.
๋กœ๊ณ  ํ…์ŠคํŠธ ์•„์ด๋”” ๋น„๋ฐ€๋ฒˆํ˜ธ์นธ ๋ฒ„ํŠผ ๋“ค์„ ํ’ˆ๊ณ  ์žˆ๋Š” container์— flex๋ฅผ ์ฃผ๊ณ  flex-direction: column ์ ์šฉ์‹œ์ผœ ์„ธ๋กœ๋กœ ์ •๋ ฌ ํ–ˆ์Šต๋‹ˆ๋‹ค.

JavaScript ์ฝ”๋“œ

const button = document.getElementById('login-button');
const idIn = document.getElementById('id-email');
const passwordIn = document.getElementById('password');
const validity = document.getElementsByClassName("validity")[0]
const container = document.getElementsByClassName("container")[0]

// id์— @ password 5์ž์ด์ƒ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ฐ ๋ฒ„ํŠผํ™œ์„ฑํ™”
function login() {
  const id= idIn.value
  const password = passwordIn.value
  if (id.includes("@") && (password.length >= 5)) {
    button.classList.remove("button-off")
    button.disabled = false;
    validity.style.display = 'none';
    } else {
    button.classList.add("button-off")
    button.disabled = true;
    validity.style.display = 'block';
  }
}
// ์—”ํ„ฐ ์น˜๋ฉด ๋ฒ„ํŠผ ํด๋ฆญ
function enter(e) {
  if(e.keyCode == 13) {
    button.click();
  }
}

container.addEventListener('keyup',login);
// idIn.addEventListener('keyup',login);
container.addEventListener('keypress',enter);
// idIn.addEventListener('keypress',enter);

  • class ์™€ id ๋ช…์œผ๋กœ ๋กœ๊ทธ์ธ๋ฒ„ํŠผ, ์•„์ด๋””, ๋น„๋ฐ€๋ฒˆํ˜ธ, ์ธํ’‹์ฐฝ์„ ์ง€์ •ํ•ด๋†“๊ณ  ๋กœ๊ทธ์ธ์ด๋ผ๋Š” ํ•จ์ˆ˜ ์•ˆ์—
    id์นธ์— @ ์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ ์นธ์ด 5์ž๋ฆฌ ์ด์ƒ์„ ํ™•์ธํ•˜๋Š” ์กฐ๊ฑด๋ฌธ์„ ๋„ฃ์Œ
  • ์ „๋ถ€ ๋งž์œผ๋ฉด ํด๋ž˜์Šค๋ช…button-off ์„ ์‚ญ์ œ,disabled ์—false ๊ฐ’์„ ์ค˜์„œ ๋ฒ„ํŠผ ํ™œ์„ฑํ™”
  • ์•„์ด๋”” ๋˜๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ž˜๋ชป ์ž…๋ ฅ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ€ ๋“ค์–ด ์žˆ๋Š” divํƒœ๊ทธ๋ฅผdisplay : none์„ ์ ์šฉ
  • ๊ทธ์™ธ์— ์กฐ๊ฑด์ด ์„ฑ์‚ฌ๋˜์ง€ ์•Š์œผ๋ฉด ์ „๋ถ€ ๋ฐ˜๋Œ€๋กœ ํ•ด์ฃผ์–ด ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ํ•จ์ˆ˜๋ฅผ ๋„ฃ์–ด์คŒ.
  • ์—”ํ„ฐ์น˜๋ฉด ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋Š” ํ•จ์ˆ˜ enter์„ ๋„ฃ์–ด์คŒ

์งง์€ ํšŒ๊ณ 

์ž‘์€ ๋กœ๊ทธ์ธํŽ˜์ด์ง€๋ฅผ ํด๋ก ํ•ด๋ณด๋ฉด์„œ ๊ทธ๋ž˜๋„ ์ต์ˆ™ํ•˜์ง€ ์•Š์•˜๋˜ flex ๊ฐœ๋…๋„ ๋‹ค์‹œ ์žก๊ณ  ์ด๋ฒคํŠธ๋ฅผ ๋„ฃ์–ด๋ณด๋Š”๊ฑธ ์ฒ˜์Œํ•ด๋ณด๋ฉด์„œ ์–ด๋–ค์‹์œผ๋กœ ์ ์šฉ๋˜๋Š”์ง€ ์•Œ์•„ ๊ฐˆ์ˆ˜์žˆ์–ด์„œ ์ข‹์€ ๊ฒฝํ—˜์ด์˜€๋‹ค๊ณ  ์ƒ๊ฐ์„ ํ•œ๋‹ค. ๋‹ค์Œ ๋ฉ”์ธํ™”๋ฉด์— ๋Œ€ํ•ด ๊ธ€์„ ์“ธ๋•Œ๋Š” ์ข€๋” ์ •๋ฆฌ๋˜๊ณ  ๋‚ด๊ฐ€ ์–ด๋–ค ์ƒ๊ฐ์„ํ•˜๋ฉด์„œ ์ด๋Ÿฐ ์ฝ”๋“œ๋ฅผ ํ–ˆ๋Š”์ง€ ์ ์–ด๋ด์•ผ ๊ฒ ๋‹ค.

profile
์Œ์•… ์ „๊ณต ์ด์˜€๋˜ ์˜ˆ๋น„ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์žโ˜€๏ธ

0๊ฐœ์˜ ๋Œ“๊ธ€