【问题标题】:how to properly control css3 animation speed如何正确控制css3动画速度
【发布时间】:2017-06-12 03:46:06
【问题描述】:

我借用了一个 css3“工作旋转”动画,其中给定的“工作每 3 秒旋转一次。 我试图通过操纵 css 动画延迟值将其加速到 1.5 秒,但我最终只是让这些词相互碰撞,而不是替换。

这是css:

#sentence-wrapper{
    width: 80%;
    position: relative;
    margin: 50px auto 0 auto;
    font-family: Georgia, serif;
    padding: 10px;
}
.sentence{
    margin: 0;
    text-align: left;
    text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
}
.sentence span{
    color: #444;
    font-size: 150%;
    font-weight: bold;
}
.words{
    display: inline;
    text-indent: 10px;
}
.words-1 span{
    position: absolute;
    margin-top: 10px;
    opacity: 0;
    overflow: hidden;
    color: #6b969d;
    -webkit-animation: rotateWord 18s linear infinite 0s;
    -moz-animation: rotateWord 18s linear infinite 0s;
    -o-animation: rotateWord 18s linear infinite 0s;
    -ms-animation: rotateWord 18s linear infinite 0s;
    animation: rotateWord 18s linear infinite 0s;
}
.words-1 span:nth-child(2) {
    -webkit-animation-delay: 3s;
    -moz-animation-delay: 3s;
    -o-animation-delay: 3s;
    -ms-animation-delay: 3s;
    animation-delay: 3s;
    color: #6b889d;
}
.words-1 span:nth-child(3) {
    -webkit-animation-delay: 6s;
    -moz-animation-delay: 6s;
    -o-animation-delay: 6s;
    -ms-animation-delay: 6s;
    animation-delay: 6s;
    color: #6b739d;
}
.words-1 span:nth-child(4) {
    -webkit-animation-delay: 9s;
    -moz-animation-delay: 9s;
    -o-animation-delay: 9s;
    -ms-animation-delay: 9s;
    animation-delay: 9s;
    color: #7a6b9d;
}
.words-1 span:nth-child(5) {
    -webkit-animation-delay: 12s;
    -moz-animation-delay: 12s;
    -o-animation-delay: 12s;
    -ms-animation-delay: 12s;
    animation-delay: 12s;
    color: #8d6b9d;
}
.words-1 span:nth-child(6) {
    -webkit-animation-delay: 15s;
    -moz-animation-delay: 15s;
    -o-animation-delay: 15s;
    -ms-animation-delay: 15s;
    animation-delay: 15s;
    color: #9b6b9d;
}
@-webkit-keyframes rotateWord {
    0% { opacity: 0; }
    2% { opacity: 0; -webkit-transform: translateY(-30px); }
    5% { opacity: 1; -webkit-transform: translateY(0px);}
    17% { opacity: 1; -webkit-transform: translateY(0px); }
    20% { opacity: 0; -webkit-transform: translateY(30px); }
    80% { opacity: 0; }
    100% { opacity: 0; }
}
@-moz-keyframes rotateWord {
    0% { opacity: 0; }
    2% { opacity: 0; -moz-transform: translateY(-30px); }
    5% { opacity: 1; -moz-transform: translateY(0px);}
    17% { opacity: 1; -moz-transform: translateY(0px); }
    20% { opacity: 0; -moz-transform: translateY(30px); }
    80% { opacity: 0; }
    100% { opacity: 0; }
}
@-o-keyframes rotateWord {
    0% { opacity: 0; }
    2% { opacity: 0; -o-transform: translateY(-30px); }
    5% { opacity: 1; -o-transform: translateY(0px);}
    17% { opacity: 1; -o-transform: translateY(0px); }
    20% { opacity: 0; -o-transform: translateY(30px); }
    80% { opacity: 0; }
    100% { opacity: 0; }
}
@-ms-keyframes rotateWord {
    0% { opacity: 0; }
    2% { opacity: 0; -ms-transform: translateY(-30px); }
    5% { opacity: 1; -ms-transform: translateY(0px);}
    17% { opacity: 1; -ms-transform: translateY(0px); }
    20% { opacity: 0; -ms-transform: translateY(30px); }
    80% { opacity: 0; }
    100% { opacity: 0; }
}
@keyframes rotateWord {
    0% { opacity: 0; }
    2% { opacity: 0; transform: translateY(-30px); }
    5% { opacity: 1; transform: translateY(0px);}
    17% { opacity: 1; transform: translateY(0px); }
    20% { opacity: 0; transform: translateY(30px); }
    80% { opacity: 0; }
    100% { opacity: 0; }
}

这是我目前的小提琴:

https://jsfiddle.net/eugene_goldberg/2y81qLd6/

如何正确调整这些设置,让旋转需要 1.5 秒而不是 3 秒?

【问题讨论】:

  • 将动画持续时间更改为值的一半 18s / 2 = 9s

标签: css animation


【解决方案1】:

将主要持续时间和所有延迟更改为一半。

.words-1 span{
    position: absolute;
    margin-top: 10px;
    opacity: 0;
    overflow: hidden;
    color: #6b969d;
    -webkit-animation: rotateWord 9s linear infinite 0s;
    -moz-animation: rotateWord 9s linear infinite 0s;
    -o-animation: rotateWord 9s linear infinite 0s;
    -ms-animation: rotateWord 9s linear infinite 0s;
    animation: rotateWord 9s linear infinite 0s;
}
.words-1 span:nth-child(2) {
    -webkit-animation-delay: 1.5s;
    -moz-animation-delay: 1.5s;
    -o-animation-delay: 1.5s;
    -ms-animation-delay: 1.5s;
    animation-delay: 1.5s;
    color: #6b889d;
}
.words-1 span:nth-child(3) {
    -webkit-animation-delay: 3s;
    -moz-animation-delay: 3s;
    -o-animation-delay: 3s;
    -ms-animation-delay: 3s;
    animation-delay: 3s;
    color: #6b739d;
}
.words-1 span:nth-child(4) {
    -webkit-animation-delay: 4.5s;
    -moz-animation-delay: 4.5s;
    -o-animation-delay: 4.5s;
    -ms-animation-delay: 4.5s;
    animation-delay: 4.5s;
    color: #7a6b9d;
}
.words-1 span:nth-child(5) {
    -webkit-animation-delay: 6s;
    -moz-animation-delay: 6s;
    -o-animation-delay: 6s;
    -ms-animation-delay: 6s;
    animation-delay: 6s;
    color: #8d6b9d;
}
.words-1 span:nth-child(6) {
    -webkit-animation-delay: 7.5s;
    -moz-animation-delay: 7.5s;
    -o-animation-delay: 7.5s;
    -ms-animation-delay: 7.5s;
    animation-delay: 7.5s;
    color: #9b6b9d;
}

https://jsfiddle.net/gaby/2y81qLd6/1/更新了演示

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 2019-02-14
    • 2018-01-15
    • 1970-01-01
    • 2013-08-13
    相关资源
    最近更新 更多