jQuery + RGBA 颜色动画

IT技术 javascript jquery animation
2021-03-04 18:08:22

有谁知道 jQuery 是否可以处理如下动画:

rgba(0,0,0,0.2) → rgba(0,255,0,0.4)

我知道有一个插件可以处理彩色动画,但这可能太现代了?

3个回答

使用 CSS3 动画(无 javascript)

您也可以使用 CSS3 动画实现相同的效果。见下文,

第 1 步:为动画创建关键帧

@keyframes color_up {
    from {
        background-color: rgba(0,0,0,0.2);
    }
    to {
        background-color: rgba(0,255,0,0.4);
    }
}

第 2 步:使用动画规则。

  animation-name: color_up;
  animation-duration: 2s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
  animation-timing-function: ease-in-out;

演示: http : //jsfiddle.net/2Dbrj/3/

使用 jQuery

jQuery 现在也支持带有RGBA支持的彩色动画这实际上是从一种颜色动画到另一种颜色。

$(selector).animate({
  backgroundColor: 'rgba(0,255,0,0.4)'
});

演示http : //jsfiddle.net/2Dbrj/2/

@DjangoReinhardt 用 CSS3 更新了答案
2021-04-16 18:08:22
更好的解决方案!!
2021-04-18 18:08:22
CSS3 JSFiddle 似乎不想在 Chrome 中工作。谢谢,不过!
2021-04-21 18:08:22
@Monk 您需要为关键帧添加 -webkit- 参见jsfiddle.net/rparree/2QsL6/1
2021-05-01 18:08:22

呃,没关系。发现对 jquery 颜色插件的惊人修改。

http://pioupioum.fr/sandbox/jquery-color/

嗯,只是为那些感兴趣的人添加另一个随机的酷炫花絮。通过php图像生成的RGBA跨浏览器:leaverou.me/2009/02/bulletproof-cross-browser-rgba-backgrounds
2021-04-28 18:08:22
不幸的是,这个修改过的版本似乎不支持现代浏览器:(
2021-05-12 18:08:22

使用jquery UI来处理,$(object).animate({color : 'rgba(0,0,0,.2)'},500)