티스토리 뷰
EVENT
const h1 = document.querySelector("div.hello:first-child h1");
function handleTitleClick(){
h1.style.color = "blue";
}
function handleMouseEnter(){
h1.innerText = "mouse is here!";
}
function handleMouseLeave(){
h1.innerText = "mouse is gone!";
}
function handleWindowResize(){
document.body.style.backgroundColor = "tomato";
}
function handleWindowCopy(){
alert("copier!");
}
function handleWindowCopy(){
alert("SOS no WIFI");
}
function handleWindowCopy(){
alert("All GOOD!");
}
h1.addEventListener("click", handleTitleClick);
h1.addEventListener("mouseenter",handleMouseEnter);
h1.addEventListener("mouseleave",handleMouseLeave);
window.addEventListener("resize", handleWindowResize);
window.addEventListener("copy", handleWindowCopy);
window.addEventListener("offline", handleWindowCopy);
window.addEventListener("online", handleWindowCopy);
handelTitleClick 이라고 쓴 이유는 click이 되어야 이 함수가 실행이 되기 때문임.
이벤트와 상관없이 실행 시키려고 할 때는 handelTitleClick ()가 되겠지
Day.4 과제 제출
superEventHandler 객체에 이벤트를 모두 작성함.
// <⚠️ DONT DELETE THIS ⚠️>
import "./styles.css";
const colors = ["#1abc9c", "#3498db", "#9b59b6", "#f39c12", "#e74c3c"];
// <⚠️ /DONT DELETE THIS ⚠️>
const title = document.querySelector("body h2");
const superEventHandler = {
mouseEnter: () => {
title.innerText = "Mouse is here!";
title.style.color = colors[0];
},
mouseLeave: () => {
title.innerText = "Mouse is gone!";
title.style.color = colors[1];
},
mouseResize: () => {
title.innerText = "You just resized!";
title.style.color = colors[2];
},
mouseClick: () => {
title.innerText = "That was a right click!";
title.style.color = colors[3];
}
};
title.addEventListener("mouseenter", superEventHandler.mouseEnter);
title.addEventListener("mouseleave", superEventHandler.mouseLeave);
window.addEventListener("contextmenu", superEventHandler.mouseClick);
window.addEventListener("resize", superEventHandler.mouseResize);
'JavaScript' 카테고리의 다른 글
[노마드 바닐라JS 챌린지] Day.8~9 LOGIN (0) | 2023.05.23 |
---|---|
[노마드 바닐라JS 챌린지] Day.5 (0) | 2023.05.19 |
[노마드 바닐라JS 챌린지] Day.3 (0) | 2023.05.17 |
[노마드 바닐라JS 챌린지] Day.2 - Booleans , Arrays , Objects (0) | 2023.05.16 |
[Javascript] value 값을 가진 option 태그를 선택했을 때, 해당 값을 input의 value에 나타내기 (0) | 2023.05.05 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 티스토리챌린지
- 프로그래머스
- useEffect
- 오버로딩
- Cleanup
- 챌린지1일차
- create react app
- 자바스크립트
- 재귀함수
- Async
- ReactJS
- 오블완
- NPM
- useState
- 카카오로그인
- TypeScript
- 리액트네이티브
- await
- splice
- nomard
- 리액트
- 타입스크립트
- props
- overloading
- slice
- 노마드
- CLI
- 프로젝트회고록
- ts
- React
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함