我想将"exampleDiv"的背景颜色从原始白色背景更改为当我调用下面的代码时立即更改背景黄色然后淡出回原始白色背景.
$("#exampleDiv").animate({ backgroundColor: "yellow" }, "fast");
Run Code Online (Sandbox Code Playgroud)
但是,此代码不起作用.
我只有JQuery核心和JQuery UI链接到我的网页.
为什么上面的代码不起作用?
最终,我希望根据不同的东西动态改变渐变,但是如何使用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)
这些方法无效吗?
是否可以background-color在jQuery中设置动画,因为它不起作用.
$('#something').animate({
background :"red"
}, 1000);
Run Code Online (Sandbox Code Playgroud) 我正在尝试按照此处所述设置CSS渐变的动画,但我无法让它工作.作为一个例子,我把这个 jsfiddle 放在一起.
作为概述,似乎渐变上的CSS转换似乎不起作用.
div#Machine {
-webkit-transition: background 5s;
-moz-transition: background 5s;
-ms-transition: background 5s;
-o-transition: background 5s;
transition: background 5s;
background: rgb(71, 234, 46);
background: -moz-linear-gradient(top, rgba(71, 234, 46, 1) 0%, rgba(63, 63, 63, 1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(71, 234, 46, 1)), color-stop(100%, rgba(63, 63, 63, 1)));
background: -webkit-linear-gradient(top, rgba(71, 234, 46, 1) 0%, rgba(63, 63, 63, 1) 100%);
background: -o-linear-gradient(top, rgba(71, 234, 46, 1) 0%, rgba(63, 63, 63, …Run Code Online (Sandbox Code Playgroud)