I want to change background opacity on div based on time.
I will use css's rgba. for example 12pm is the brightest(rgba(0, 0, 0, 0)) and 12am is the darkest(rgba(0, 0, 0, 1))
and I found this script and try to modify. but it changes color and there's no opacity option.
How can I change this code?
I really need your help. Thank you.
function time() {
var today = new Date();
var h = today.getHours()
if (h > 12) {
h = h - "12"
};
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('clocky').innerHTML = h + ":" + m + ":" + s;
var r = parseInt(s) * 1;
var g = parseInt(s) * 3;
var b = parseInt(s) * 5;
document.body.style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')';
var t = setTimeout(time, 500);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i
};
return i;
}
time();