改变径向梯度的颜色

时间:2017-07-21 17:10:33

标签: javascript html css web

如何使用JavaScript将创建的红色圆圈更改为绿色圆圈?

#redcircle {
  background-image: radial-gradient(
    circle,
    red, 
    red 40px,
    transparent 20px
  );
}

1 个答案:

答案 0 :(得分:3)

选项1

重置这样的风格:

let circle = document.getElementById('redcircle');
circle.style.backgroundImage = 'radial-gradient(circle, green, green 40px, transparent 20px)';

选项2

制作另一种css样式,并替换如下样式:

#greencircle{

background-image:
radial-gradient(
circle,
green, green 40px, transparent 20px

);
let circle = document.getElementById('redcircle');
circle.id = 'greencircle';