我想通过使用jquery从渐变背景切换到元素的纯背景。通过.css获取渐变元素的css背景属性()
由于某些原因,我不能使用toggleClass和其他类方法,所以我必须修改一个元素的CSS属性 - 在我的情况下背景颜色。
问题是,当我试图接收当前的背景CSS属性,.css()方法返回一些奇怪的东西。
我有带多个背景(梯度)属性元素,为不同的浏览器
.element {
background: #ce4f57 !important;
background: -moz-linear-gradient(top, #ce4f57 0%, #b7333b 100%) !important;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ce4f57), color-stop(100%, #b7333b)) !important;
background: -webkit-linear-gradient(top, #ce4f57 0%, #b7333b 100%) !important;
background: -o-linear-gradient(top, #ce4f57 0%, #b7333b 100%) !important;
background: -ms-linear-gradient(top, #ce4f57 0%, #b7333b 100%) !important;
background: linear-gradient(to bottom, #ce4f57 0%, #b7333b 100%) !important;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ce4f57', endColorstr='#b7333b', GradientType=0) !important;
}
优化当我尝试收到财产
$('.element').css('background');
我得到这个:
rgba(0, 0, 0, 0) linear-gradient(rgb(206, 79, 87) 0%, rgb(183, 51, 59) 100%) repeat scroll 0% 0%/auto padding-box border-box
据我了解,它的编译属性?我可以通过js函数获得原始的css吗? 如果没有请告诉我如何写正则表达式来获得渐变的第一种颜色,假设有可能differenet在不同浏览器编写CSS ...
我说返回值,即您的特定浏览器当前使用.. – honk31
看起来像这样,但我需要第一种颜色来将背景从渐变变为纯色,我如何得到它? –
你的意思是你正在寻找第一个价值又名。背景:#ce4f57!重要; ? – honk31