๋ฐ์ํ
[์ถ์ฒ-์ ํ๋ธ ๋ ธ๋ง๋ ์ฝ๋ Nomad Coders]
-์ด๋ฒคํธ์ ๊ทผ์์ ์๊ณ ์ถ์ผ๋ฉด ํญ์ MDN์ ์ฐพ์๋ณด๋ผ
const title = document.querySelector("#title");
const BASE_COLOR = "rgb(52, 73, 94)";
const OTHER_COLOR = "#7f8c8d";
function handleClick(){
const currentColor = title.style.color;
console.log(currentColor);
}
function init(){
title.style.color = BASE_COLOR;
title.addEventListener("click", handleClick);
}
init();
const title = document.querySelector("#title");
const BASE_COLOR = "rgb(52, 73, 94)";
const OTHER_COLOR = "#7f8c8d";
function handleClick(){
const currentColor = title.style.color;
if (currentColor === BASE_COLOR){
title.style.color = OTHER_COLOR;
} else {
title.style.color = BASE_COLOR;
}
}
function init(){
title.style.color = BASE_COLOR;
title.addEventListener("click", handleClick);
}
init();
function init(){
title.style.color = BASE_COLOR;
title.addEventListener("mouseenter", handleClick);
}
-mouseenter๋ก ๋ฐ๊พธ๋ฉด ๋ง์ฐ์ค๋ฅผ ์ฌ๋ฆด๋๋ง๋ค ์๊น์ด ๋ฐ๋๋ค
function handleOffline(){
console.log("lalala");
}
window.addEventListener("offline", handleOffline)
-์คํ๋ผ์ธ์ผ ๋(์ธํฐ๋ท ์ฐ๊ฒฐ์ด ์๋์์๋) 'lalala'๊ฐ ์ถ๋ ฅ๋๋ค
function handleOffline(){
console.log("bye bye");
}
function handleOnline(){
console.log("welcome back");
}
window.addEventListener("offline", handleOffline)
window.addEventListener("online", handleOnline)
-์จ๋ผ์ธ์ผ ๋ 'welcome back'์ ์ถ๋ ฅํ๊ณ ์คํ๋ผ์ธ์ผ ๋ 'bye bye'๋ฅผ ์ถ๋ ฅ
๋ฐ์ํ
๋๊ธ