๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ป๋ฐ”๋‹๋ผ JS๋กœ ํฌ๋กฌ ์•ฑ ๋งŒ๋“ค๊ธฐ : #3.3-3.5

change upยท2023๋…„ 6์›” 5์ผ
3
post-custom-banner
## /*#3.3-3.4 Events
:element ๋ฅผ ์ฐพ์•„์„œ event listener ์ถ”๊ฐ€*/
//click event:addEventListener:("click",function)
const title = document.querySelector("div.hello:first-child h1");
function handleTitleClick(){
    console.log("title was clicked");
}
title.addEventListener("click",handleTitleClick);
//("click",handleTitleClick()): ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ฐ”๋กœ ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ž๋ฐ”์Šคํฌ๋ฆฝ๊ฐ€ ํด๋ฆญ์‹œ ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ()์ œ์™ธํ•˜๊ณ  ์ž‘์„ฑ.

### //mouseenter
function handleMouseEnter(){
    console.log("mouse is here");   
}
title.addEventListener("mouseenter", handleMouseEnter);

### //mouseleave
function handleMouseLeave(){
    title.innerText = "mouse is gone"; }

title.addEventListener("mouseenter", handleMouseLeave);
## /*#3.5 More window*/
### //window.resize
function handleWindowResize(){
    document.body.style.backgroundColor = "tomato";
}
window.addEventListener("resize", handleWindowResize);
### //copy 
function handleWindowCopy(){
    alert("copier!");
}
window.addEventListener("copy", handleWindowCopy);  
### //offline,online
function handleWifiOffline(){
    alert("offline!");
}
window.addEventListener("offline", handleWifiOffline);

function handleWifiOnline(){
    alert("online!");
}
window.addEventListener("online", handleWifiOnline);
profile
์ƒˆ์‹น์ด
post-custom-banner

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