【问题标题】:Animation in css with gradient colors带有渐变颜色的 css 动画
【发布时间】:2012-11-25 16:59:36
【问题描述】:

我有这个 CSS3 代码:

#box2 {
    position: relative;
    width: 500px;
    border: 1px solid black;
    box-shadow: -3px 8px 34px #808080;
    border-radius: 20px;
    box-shadow: -8px 5px 5px #888888;
    right: 300px;
    top: 113px;
    text-align: justify;
    -webkit-transition: all 1s;
    font-size: large;
    color: Black;
    padding: 10px;
    background: #D0D0D0;
    opacity: 0;
}


@-webkit-keyframes mySecond {
    0% {
        right: 300px;
        top: 13px;
        background: #D0D0D0;
        opacity: 0;
    }

    100% {
        background: #909090;
        right: 300px;
        top: 63px;
        opacity: 1;
    }
}

#littlebox2 {
    top: 053px;
    position: absolute;
    display: inline-block;
}

.littlebox2sentence {
    font-size: large;
    padding-bottom: 15px;
    padding-top: 15px;
    padding-left: 25px;
    padding-right: 10px;
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#9CCEDA), to(#58A8D8));
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    -webkit-transition: background .25s ease-in-out;
    border-bottom: 2px solid red;
    border-right: 2px solid red;
    border-top: 2px solid red;
    -webkit-transition-property: color, background;
    -webkit-transition-duration: .25s, .25s;
    -webkit-transition-timing-function: linear, ease-in-out;
    color: #164ad7;
}

#bothcontainer2:hover ~ #box2 {
    -webkit-transition: all 0s;
    background: #909090;
    right: 300px;
    top: 63px;
    -webkit-animation: mySecond .75s;
    -webkit-animation-fill-mode: initial;
    opacity: 1;
}

#bothcontainer2:hover .littlebox2sentence {
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#B2DFE9), to(#83BEF1));
    color: black;

}

此处的示例:http://jsfiddle.net/md966/3/

如何使用渐变颜色制作动画?如果颜色是蓝色和红色,它可以正常工作(背景颜色过渡),但是当我用渐变色替换它时它不起作用。我找到了一些教程,但它们并没有真正帮助我。

【问题讨论】:

    标签: css animation background gradient


    【解决方案1】:

    当使用渐变作为背景时,您不需要定义背景颜色。渐变是背景图像。 背景图像不是可以设置动画的属性。所以你的方法行不通。

    【讨论】:

    • 谢谢!好的,所以我不能用渐变色做任何动画?没有其他解决方案吗?
    • 我看到的唯一解决方案是使用具有不同背景图像绝对定位的不同容器层并淡入这些层。但我不想那样做。
    • 谢谢!那么你的建议是什么?使用带有效果的“常规”颜色或使用没有效果的渐变颜色?你认为什么更好? (我想得到一个建议!)
    • 这是您必须自己做出的决定。这在很大程度上取决于页面的完整设计以及动画是否支持对用户的重要过程的可视化。如果只是因为它很酷,那么我会完全摆脱动画。
    • 好的,非常感谢您!你真的帮了我!
    猜你喜欢
    • 2015-07-13
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 2022-06-27
    • 2021-03-12
    相关资源
    最近更新 更多