用jQuery应用css3渐变

Dav*_*ave 9 jquery gradient css3

最终,我希望根据不同的东西动态改变渐变,但是如何使用jquery来应用css3渐变呢?

 //works
 $(element).css("background-image", "url(http://www.google.co.uk/images/logos/ps_logo2.png)");  

 //doesn't work
 $(element).css("background-image","-webkit-gradient(linear,left bottom,right bottom,color-stop(0.50, rgb(194,231,255)),color-stop(0.50, rgb(255,255,255))");

 //doesn't work
 $(element).css("background-image","-moz-linear-gradient(left center,rgb(194,231,255) 28%,rgb(255,255,255) 28%");
Run Code Online (Sandbox Code Playgroud)

我错过了什么?我也试过了

 $(element).css({background: "-webkit-gradient(linear,left bottom,right bottom,color-stop(0.50, rgb(194,231,255)),color-stop(0.50, rgb(255,255,255)"});
Run Code Online (Sandbox Code Playgroud)

这些方法无效吗?

Dut*_*432 18

你的第二种方法看起来还不错......也许你需要为非webkit浏览器提供css样式...... 跨浏览器CSS渐变

适用于Chrome

$('#block').css({
    background: "-webkit-gradient(linear, left top, left bottom, from(#ccc), to(#000))" 
});
Run Code Online (Sandbox Code Playgroud)

另请查看:http://www.colorzilla.com/gradient-editor/