-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript6.js
57 lines (50 loc) · 2.24 KB
/
script6.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const tUbahWarna = document.getElementById("tUbahWarna");
// btn.addEventListener("click", function () {
// // document.body.style.backgroundColor = "lightblue";
// document.body.classList.toggle("biru-muda");
// });
const tAcakWarna = document.createElement("button");
const teksTAcakWarna = document.createTextNode("Acak Warna");
tAcakWarna.appendChild(teksTAcakWarna);
tAcakWarna.setAttribute("type", "button");
tUbahWarna.after(tAcakWarna);
tAcakWarna.addEventListener("click", function () {
const r = Math.round(Math.random() * 255 + 1);
const g = Math.round(Math.random() * 255 + 1);
const b = Math.round(Math.random() * 255 + 1);
document.body.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
});
const sMerah = document.querySelector("input[name=sMerah]");
const sHijau = document.querySelector("input[name=sHijau]");
const sBiru = document.querySelector("input[name=sBiru]");
const kMerah = document.querySelectorAll(".kotak")[0];
const kHijau = document.querySelectorAll(".kotak")[1];
const kBiru = document.querySelectorAll(".kotak")[2];
sMerah.addEventListener("input", function () {
const r = sMerah.value;
const g = sHijau.value;
const b = sBiru.value;
document.body.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
// kMerah.style.backgroundColor = "rgb(" + r + ",100,100)";
});
sHijau.addEventListener("input", function () {
const r = sMerah.value;
const g = sHijau.value;
const b = sBiru.value;
document.body.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
// kMerah.style.backgroundColor = "rgb(" + r + ",100,100)";
// kHijau.style.backgroundColor = "rgb(100," + g + ",100)";
});
sBiru.addEventListener("input", function () {
const r = sMerah.value;
const g = sHijau.value;
const b = sBiru.value;
document.body.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
// kBiru.style.backgroundColor = "rgb(100,100," + b + ")";
});
document.body.addEventListener("mousemove", function (event) {
const xPos = Math.round((event.clientX / window.innerWidth) * 255 + 1);
const yPos = Math.round((event.clientY / window.innerHeight) * 255 + 1);
const b = Math.round(Math.random() * 255 + 1);
document.body.style.backgroundColor = "rgb(" + xPos + "," + yPos + ",255)";
});