// κ°μ λ¬Έμμ΄λ‘ νκΈ°νλ€.
box1.style = "color: blue;"; //BOM
box1.setAttribute("style", "color:red"); //DOM
box1.style = "color:blue;";
box1.style.fontSize = "2rem"
// 맡 ννλ‘λ κ°λ₯. μ΄λ κ² μ¬μ©νλ©΄ μΉ΄λ©νκΈ°λ²μΌλ‘ λ³κ²½νμ§ μμλ λλ€.
box1.style["color"] = "gold";
box1.style["background-image"] = "url(../asset/images/catty01.png)";
box1.style.width = parseInt(box1.style.width) + 50 + "px";
//CSS μ μ© λ°©μ λ¬΄κ΄ > νμ¬ κ°μ²΄μ μ μ©λ λͺ¨λ CSS μμ±μ λ°ν
const list = window.getComputedStyle(box1);
alert(box1.style.width); // null -> μΈλΌμΈμ΄ μλλ©΄ λͺ»μ½μ΄μ¨λ€.
alert(list.width); // 200px
alert(list.getPropertyValue("width")); // 200px
//2λ² λ°©λ²
// ν΄λμ€ 1κ°μΌ λ μ¬μ©
// <p class="one two">
// <p class="one two three">
// content.className += " three";
// ν΄λμ€ μ¬λ¬κ° μΌ λ μ¬μ©
content.classList.add("three");
content.classList.remove("two");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box {
width: 150px;
height: 150px;
position: absolute;
left: 0;
top: 0;
}
#box1 {
background-color: tomato;
}
#box2 {
background-color: orange;
}
#box3 {
background-color: gold;
}
#box4 {
background-color: greenyellow;
}
#box5 {
background-color: cornflowerblue;
}
</style>
</head>
<body>
<!-- ex52_css.html -->
<div id="box1" class="box">μμ1</div>
<div id="box2" class="box">μμ2</div>
<div id="box3" class="box">μμ3</div>
<div id="box4" class="box">μμ4</div>
<div id="box5" class="box">μμ5</div>
<script>
const list = document.getElementsByClassName("box");
let index = 0;
let zindex = 1;
window.onmousedown = () => {
// μμ > postion(absolute) > λ¬Έμ μ’μΈ‘ μλ¨ κΈ°μ€
// clientX, clientY > λ¬Έμ μ’μΈ‘ μλ¨ κΈ°μ€
// alert(event.clientX);
list[index].style.left = event.clientX - 75 + "px"; // νμ¬ ν΄λ¦ν xμ’ν
list[index].style.top = event.clientY - 75 + "px";
list[index].style.zIndex = zindex;
index++;
zindex++;
if (index >= list.length) index = 0;
};
</script>
</body>
</html>
window.onmousedown = () => {
if (event.buttons == 1) {
const box = document.createElement("div");
box.className = "box";
box.style.left = event.clientX - 75 + "px";
box.style.top = event.clientY - 75 + "px";
let r = parseInt(Math.random() * 256);
let g = parseInt(Math.random() * 256);
let b = parseInt(Math.random() * 256);
box.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
document.body.appendChild(box);
} else if (event.buttons == 2) {
document.body.removeChild(event.target);
}
};
window.oncontextmenu = () => false;
absolute
λλκ·Έ μ€ λλ relative
λλκ·Έ μ€ λλ absolute2
λλκ·Έ μ€ λλ relative2
μμ ν¬κΈ° μ‘°μ
μμ νμ
const item = document.querySelectorAll("#menu > img");
let olditem = null;
for (let i = 0; i < item.length; i++) {
item[i].onclick = () => {
if (olditem != null) {
//λ©λ΄ 1κ°κ° μ΄λ €μλ€.
olditem.style.transform = "translate(0px, 0px)";
}
if (event.target != olditem) {
event.target.style.transform = "translate(0px, 90px)";
olditem = event.target;
} else {
event.target.style.transform = "translate(0px, 0px)";
olditem = null;
}
};
}
const list = document.getElementById("list");
const sel1 = document.getElementById("sel1");
let dist = 0;
sel1.addEventListener("change", () => {
// alert(sel1.value);
list.style.transform = `translate(-${sel1.value * 250}px, 0px)`;
});
// μ«μν€ μ
λ ₯
window.onkeydown = () => {
list.style.transform = `translate(-${
(event.keyCode - 49) * 250
}px, 0px)`;
};
const puma = document.getElementById("puma");
x = 0;
let y = 0;
let timer = 0;
puma.onclick = () => {
if (timer == 0) {
timer = setInterval(() => {
x -= 512;
if (x < -512 * 3) {
x = 0;
y -= 256;
if (y < -256) {
y = 0;
}
}
puma.style.backgroundPosition = `${x}px ${y}px`;
}, 100);
} else {
clearInterval(timer);
timer = 0;
}
};
//μ€ν¬λ‘€ μ΄λ²€νΈ
window.onscroll = () => {
if (window.scrollY > 1500 && window.scrollY <= 2500) {
document.body.style.backgroundColor = "black";
document.body.style.color = "white";
} else {
document.body.style.backgroundColor = "white";
document.body.style.color = "black";
}
};
λ‘κ·ΈμΈ νμ λ Authμ λ‘κ·ΈμΈ ν μ¬μ©μμ idλ₯Ό μ μ₯νλ κΈ°λ₯μ λ§λ€μλ€.
λ‘κ·ΈμΈ, μμ΄λ κ²μ, λΉλ°λ²νΈ μμ μ μ‘°ννλ €λ νμμ΄ νν΄ν νμμΈμ§ νμΈνλ μμ μ μΆκ°νλ€. νν΄ν νμμ ν΄λΉ κΈ°λ₯μ ν μ μκ² μ€μ νλ€.
νλ‘κ·Έλλ¨Έμ€μ ν°μΌλͺ¬ λ¬Έμ λ₯Ό νμλ€. mapκ³Ό setμΌλ‘ νμ΄λ³΄μλ€.