我怎么会去设置一个JavaScript CSS渐变背景?

问题描述 投票:0回答:2

CSS的梯度描述here,但我不知道如何选择在JavaScript这些属性。如果可能的话,我宁愿不使用jQuery这一点。

编辑:只是执行以下操作似乎并没有工作...

document.getElementById("selected-tab").style.background = "#860432";
document.getElementById("selected-tab").style.background = "-moz-linear-gradient(#b8042f, #860432)";
document.getElementById("selected-tab").style.background = "-o-linear-gradient(#b8042f, #860432)";
document.getElementById("selected-tab").style.background = "-webkit-gradient(linear, 0% 0%, 0% 100%, from(#b8042f), to(#860432))";
document.getElementById("selected-tab").style.background = "-webkit-linear-gradient(#b8042f, #860432)";
javascript css3
2个回答
1
投票

我不是一个JS专家,但我的猜测是,您的设置相互覆盖,所以你可能要创建这个喜欢.gradientBackground一个CSS类选择,并检查了下面的链接:

Change an element's class with JavaScript


0
投票

如果你不想使用jQuery你想如何应用的样式?你应该创建其中包含了每种浏览器的梯度类或ID。然后使用jQuery该类设置为ID“选择选项卡”

.someGradient{
    background: #1e5799; /* Old browsers */
    background: -moz-linear-gradient(top,  #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */
    background: linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
}

jQuery的

$("#selected-tab").addClass('someGradient');

之前

 <div id='selected-tab' class='arial'>Hello world</div>

 <div id='selected-tab' class='arial someGradient'>Hello world</div>
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.