我正在尝试使用JavaScript将我的网站背景更改为不同颜色的线性渐变。 背景正在更改,但变成了纯色,而不是线性渐变。
我记录了背景,并显示出新的线性渐变,因此我“知道”它正在设置样式。
我记录了背景,并显示出新的线性渐变,因此我“知道”它正在设置样式。
body {
padding: 0;
margin: 0;
font-family: 'Kosugi Maru', sans-serif;
background-image: linear-gradient(45deg, rgb(140, 202, 165),
rgb(198,159,197), rgb(248, 160, 133), rgb(52,219,216));
}
function generateGradient(one, two, three) {
let lessOne = one;
let moreOne = one;
let lessTwo = two;
let moreTwo = two;
let lessThree = three;
let moreThree = three;
if (one >= 10) {
lessOne = one - 10;
}
if (two >= 10) {
lessTwo = two - 10;
}
if (three >= 10) {
lessThree = three - 10;
}
if (one <= 245) {
moreOne = one + 10;
}
if (two <= 245) {
moreTwo = two + 10;
}
if (three <= 245) {
moreThree = three + 10;
}
document.getElementsByTagName("body")[0].style.backgroundImage = 'linear-gradient(45deg, rgb(' + lessOne + ',' + lessTwo + ',' + lessThree + '), rgb(' + one + ',' + two + ',' + three + '), rgb(' + moreOne + ',' + moreTwo + ',' + moreThree + '))';
}