[miniProjects] 04_Hidden Search Widget

๋ณด๋ฆฌยท2023๋…„ 6์›” 16์ผ
0

miniProjects

๋ชฉ๋ก ๋ณด๊ธฐ
5/47

04_Hidden Search Widget

๐Ÿ’ป ์ฃผ์ œ : ๋‹๋ณด๊ธฐ๋ฅผ ๋ˆ„๋ฅด๋ฉด ๊ฒ€์ƒ‰ ์ฐฝ์ด ๋Š˜์–ด๋‚จ.

  • ํ† ๊ธ€ ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ๋ฒ„ํŠผ์„ ํด๋ฆญ ์‹œ active๋ผ๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•จ.

const search = document.querySelector('.search');
const btn = document.querySelector('.btn');
const input = document.querySelector('.input');

btn.addEventListener('click', () => {
  search.classList.toggle('active');
  input.focus();
})

โ—toggle()

ํ† ๊ธ€์ด๋ž€ add(), remove() ๋ฉ”์„œ๋“œ๋ฅผ ํ•œ ๋ฒˆ์— ์“ธ ์ˆ˜ ์žˆ์Œ. ๋ณดํ†ต click ์ด๋ฒคํŠธ์— classList๋ฅผ ์ด์šฉํ•ด toggle๋กœ css์— style์„ ์ค€ ํด๋ž˜์Šค๋ช…์„ on/off ํ•จ.

profile
์ •์‹ ์ฐจ๋ ค ์ด ๊ฐ๋ฐ•ํ•œ ์„ธ์ƒ์†์—์„œ

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