-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5_warna.js
78 lines (51 loc) · 1.9 KB
/
5_warna.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
58
59
60
const tUbahWarna = document.getElementById('tUbahWarna');
tUbahWarna.onclick = function() {
// document.body.style.backgroundColor = 'lightblue';
// document.body.setAttribute('class', 'biru-muda');
document.body.classList.toggle('biru-muda');
}
const tAcakWarna = document.createElement('button');
const textTombol = document.createTextNode('Acak Warna');
tAcakWarna.appendChild(textTombol);
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]');
sMerah.addEventListener('input', function() {
const r = sMerah.value;
const g = sHijau.value;
const b = sBiru.value;
document.body.style.backgroundColor = 'rgb('+ r +', '+ g +', '+ b +')';
});
sHijau.addEventListener('input', function() {
const r = sMerah.value;
const g = sHijau.value;
const b = sBiru.value;
document.body.style.backgroundColor = 'rgb('+ r +', '+ g +', '+ b +')';
});
sBiru.addEventListener('input', function() {
const r = sMerah.value;
const g = sHijau.value;
const b = sBiru.value;
document.body.style.backgroundColor = 'rgb('+ r +', '+ g +', '+ b +')';
});
document.body.addEventListener('mousemove', function(event) {
/*
posisi mouse
console.log(event.clientX);
*/
/*
ukuran browser
console.log(window.innerWidth);
*/
const xPos = Math.round((event.clientX / window.innerWidth) * 255);
const yPos = Math.round((event.clientY / window.innerHeight) * 255);
document.body.style.backgroundColor = 'rgb('+ xPos +', '+ yPos +', 100)';
})