Javascript jQuery + RGBA 颜色动画

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3242368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:50:02  来源:igfitidea点击:

jQuery + RGBA color animations

javascriptjqueryanimation

提问by Matrym

Does anyone know if jQuery can handle an animation like:

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

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

I know there is a pluginto handle color animations, but this might be too modern?

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

采纳答案by Matrym

Uh, nevermind. Found an amazing modification to the jquery color plugin.

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

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

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

回答by Selvakumar Arumugam

Using CSS3 animation(no javascript)

使用 CSS3 动画(无 javascript)

You can also achieve the same effect using CSS3 animation. See below,

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

Step 1:Create a keyframe for your animation

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

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

Step 2:Use the animation rules.

第 2 步:使用动画规则。

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

DEMO:http://jsfiddle.net/2Dbrj/3/

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

Using jQuery

使用 jQuery

jQuery now supports coloranimationwith RGBAsupport as well. This actually animates from one color to other.

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

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

DEMO: http://jsfiddle.net/2Dbrj/2/

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

回答by ilovebali

use jquery UIfor handle that, $(object).animate({color : 'rgba(0,0,0,.2)'},500)

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