๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ป/Nomadcoders

vanilla JS Challenges 2022/03/07~2022/03/21

<2022.03.10>

 

๊ฐ์ฒด ์•ˆ์— ๋ฉ”์„œ๋“œ ์„ ์–ธํ•˜๊ธฐ

const object = {
	handleMousEnter: function(){
    ///
    },
    handleMouseLeave: function(){
    ///
    }
};

์‚ฌ์šฉํ•œ Event

- mouseenter, mouserleave, resize, contextmenu

h2.addEventListener("mouseenter", superEventHandler.handleEnter);
h2.addEventListener("mouseleave", superEventHandler.handleLeave);
window.addEventListener("resize", superEventHandler.handleResize);
window.addEventListener("contextmenu", superEventHandler.handleContext);

์ด๋ฒคํŠธ๋ฅผ ๋ฆฌ์Šค๋„ˆํ•˜๋Š” ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•

h2.addEventListener("mouseenter", superEventHandler.handleEnter);

๋˜๋Š”

h2.onmouseenter = superEventHandler.handlerEnter;

 

<2022.03.11>

 

js ํŒŒ์ผ์—์„œ css๋ฅผ ๊ฑด๋“œ๋ฆฌ๊ณ  ์‹ถ์ง€ ์•Š์•„, class๋ฅผ ํ• ๋‹นํ•˜์—ฌ css๋ฅผ ๋ณ€๊ฒฝํ•ด๋ณด์ž.

 

className์œผ๋กœ ์ „์ฒด className์œผ๋กœ ๋ณ€๊ฒฝํ•ด๋ฒ„๋ฆฌ๋ฉด ์›๋ž˜ ๊ฐ€์ง€๊ณ  ์žˆ๋˜ class๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์—†๊ฒŒ ๋˜๋ฏ€๋กœ

classList๋ฅผ ์‚ฌ์šฉํ•ด className์„ add removeํ•˜์ž.

 

const body = document.querySelector("body");

function handleWindowResize() {
  const windowSize = window.innerWidth;
  const bodyClassName = body.classList;

  if (windowSize < 600) {
    bodyClassName.add("short");
    bodyClassName.remove("long", "medium");
  } else if (windowSize < 800) {
    bodyClassName.add("medium");
    bodyClassName.remove("long", "short");
  } else {
    bodyClassName.add("long");
    bodyClassName.remove("short", "medium");
  }
}

window.addEventListener("resize", handleWindowResize);

 

<2022.03.14>

 

- and๋กœ ํ•œ์ค„ ์ •๋ ฌ

      <h3>Generate a number between 0 and
      <input required min="0" type="number" placeholder="" />

 

- ์ตœ์†Ÿ๊ฐ’, type

<input required min="0" id="guess-input" type="number" />

 

- preventDefault() - > ํƒœ๊ทธ์˜ ๊ธฐ๋ณธ ๋™์ž‘์„ ๋ง‰์Œ 

 

- Math

round: ๋ฐ˜์˜ฌ๋ฆผ

ceil: ์˜ฌ๋ฆผ

floor: ๋‚ด๋ฆผ

 

- submit event

form ํƒœ๊ทธ๋ฅผ ์ ์šฉ๋˜๋Š” 

form์˜ ์ •๋ณด๋ฅผ ์„œ๋ฒ„๋กœ ์ „์†กํ•˜๋Š” ๋ช…๋ น

 

 

<2022.03.16>

- new Date();

๋‚ ์งœ์™€ ์‹œ๊ฐ„(๋…„, ์›”, ์ผ, ์‹œ, ๋ถ„, ์ดˆ, ๋ฐ€๋ฆฌ์ดˆ)์„ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋นŒํŠธ์ธ ๊ฐ์ฒด, ์ƒ์„ฑ์ž ํ•จ์ˆ˜ 

  • ์•„๋ฌด๋Ÿฐ ์ธ์ž๋ฅผ ์ „๋‹ฌํ•˜์ง€ ์•Š์œผ๋ฉด ํ˜„์žฌ ๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ๊ฐ€์ง€๋Š” ์ธ์Šคํ„ด์Šค ๋ฆฌํ„ด

 

- getTime()

1970๋…„ 1์›” 1์ผ 0์‹œ 0๋ถ„ 0์ดˆ๋ถ€ํ„ฐ ํ˜„์žฌ๊นŒ์ง€์˜ ์‹œ๊ฐ„์„ ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„๋กœ ํ™˜์‚ฐํ•œ ๊ฐ’์„ ์ˆซ์ž๋กœ ๋ฐ˜ํ™˜

 

- padStart(Length, String)

ํ˜„์žฌ ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘์„ String์œผ๋กœ ์ฑ„์›Œ ์ฃผ์–ด์ง„ Length์— ๋งž๋Š” ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜

 

- setInterval(function, ms)

์ผ์ • ์‹œ๊ฐ„ ๊ฐ„๊ฒฉ์„ ๋‘๊ณ  ๊ณ„์†ํ•ด์„œ ํ•จ์ˆ˜ ๋ฐ˜๋ณต ์‹คํ–‰ 

 

- setTimeout(functiom, ms)

์˜๋„์ ์œผ๋กœ ํ•จ์ˆ˜ ์‹คํ–‰์„ ์ง€์—ฐ์‹œ์ผœ ์ผ์ • ์‹œ๊ฐ„ํ›„์— ์‹คํ–‰ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜

 

 

'๐Ÿ’ป > Nomadcoders' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

HTML Form  (0) 2022.03.18
[React JS] Arrow function์ด๋ž€?  (0) 2022.02.22