【发布时间】:2017-02-20 17:40:48
【问题描述】:
我想使用线性渐变制作一个圆形背景以逐渐填充。我有我的 CSS 和 JavaScrpit 文件,只是我不知道如何在 JS 中选择线性渐变属性。
<div id="circle" class="circleBase "></div>
#circle{
width: 300px;
height: 300px;
background-color:blue;
background: linear-gradient(90deg, #FFC0CB 0%,white 100%);
}
function changeBackground() {
var elem = document.getElementById("circle");
var width = 1;
var id = setInterval(frame, 10);
function frame() {
if (width >= 100) {
clearInterval(id);
} else {
width++;
elem.style = ????
}
}
}
【问题讨论】:
-
你的 CSS 选择器还能工作吗?元素的 ID 是
type3,而不是circle! -
类似这样的东西:
elem.style.backgroundImage = "linear-gradient(90deg, #FFC0CB " + from + "%, white " + to + "%); -
已编辑:我在那里使用圆圈
标签: javascript html css linear-gradients