Javascript 无法更新渐变
Javascript Can't Update Gradient
我似乎无法更新应用到导航栏的线性渐变。它工作正常,当我
像这样在我的 css 文件中设置它
.navbar-light {
background-image: linear-gradient(rgba(255, 204, 153, 1), 75%, rgba(255, 204, 153, 0));
}
但它似乎无法通过 Javascript 工作,即使我可以像这样在同一个函数中设置其他属性
function myFunc() {
var nav = document.getElementById("myNavbar");
nav.style.backgroundImage = "linear-gradient(rgba(255, 204, 153, 1), 90%, rgba(255, 204, 153, 0));"
console.log(nav.style.backgroundImage);
}
我做错了什么?
呃那些分号 :P
(function myFunc() {
var nav = document.getElementById("myNavbar");
nav.style.backgroundImage = "linear-gradient(rgba(255, 204, 153, 1), 90%, rgba(255, 204, 153, 0))" // look on your code here
})()
.navbar-light {
background-image: linear-gradient(rgba(255, 204, 153, 1), 75%, rgba(255, 204, 153, 0));
}
div.box{
width: 100px;
height: 100px;
border: 1px solid black;
}
<div class="box navbar-light"> 1 </div>
<div id="myNavbar" class="box"/> 2 </div>
我似乎无法更新应用到导航栏的线性渐变。它工作正常,当我 像这样在我的 css 文件中设置它
.navbar-light {
background-image: linear-gradient(rgba(255, 204, 153, 1), 75%, rgba(255, 204, 153, 0));
}
但它似乎无法通过 Javascript 工作,即使我可以像这样在同一个函数中设置其他属性
function myFunc() {
var nav = document.getElementById("myNavbar");
nav.style.backgroundImage = "linear-gradient(rgba(255, 204, 153, 1), 90%, rgba(255, 204, 153, 0));"
console.log(nav.style.backgroundImage);
}
我做错了什么?
呃那些分号 :P
(function myFunc() {
var nav = document.getElementById("myNavbar");
nav.style.backgroundImage = "linear-gradient(rgba(255, 204, 153, 1), 90%, rgba(255, 204, 153, 0))" // look on your code here
})()
.navbar-light {
background-image: linear-gradient(rgba(255, 204, 153, 1), 75%, rgba(255, 204, 153, 0));
}
div.box{
width: 100px;
height: 100px;
border: 1px solid black;
}
<div class="box navbar-light"> 1 </div>
<div id="myNavbar" class="box"/> 2 </div>