javascript - 如何在CSS中使用关键帧文本动画时设置填充文本

标签 javascript html css animation

我有一个文本向上/向下滑动动画。

我在文本动画时遇到填充问题。

当动画未在中心正确显示时显示文本。

我希望所有文本都显示在中心。

你可以在这里看到代码:

.flipword {
    color: #999;
    text-transform: uppercase;
    font-size: 36px;
    font-weight: bold;
    /* padding-top: 200px; */
    /* position: fixed; */
    padding-bottom: 15px;
    width: 100%;
    bottom: 45%;
    display: block;
}

#flip {
    height: 65px;
    overflow: hidden;
}

#flip>div>div {
    color: #fff;
    padding: 4px 12px;
    height: 60px;
    margin-bottom: 45px;
    display: inline-block;
}

#flip div:first-child {
    animation: show 10s linear infinite;
}

#flip div div {
    background: #42c58a;
}

#flip div:first-child div {
    background: #4ec7f3;
}

#flip div:last-child div {
    background: #DC143C;
}

@keyframes show {
    0% {
        margin-top: -270px;
    }
    5% {
        margin-top: -180px;
    }
    33% {
        margin-top: -180px;
    }
    38% {
        margin-top: -90px;
    }
    66% {
        margin-top: -90px;
    }
    71% {
        margin-top: 0px;
    }
    99.99% {
        margin-top: 0px;
    }
    100% {
        margin-top: -270px;
    }
}
<div class="flipword">
  <div id="flip">
    <div><div>Not Center</div></div>
    <div><div>Is Center</div></div>
    <div><div>Not Center</div></div>
  </div>
</div>

最佳答案

你的CSS应该是这样的。看看https://jsfiddle.net/tamvo/m25b1vLa/

.flipword {
    color: #999;
    text-transform: uppercase;
    font-size: 36px;
    font-weight: bold;
    /* padding-top: 200px; */
    /* position: fixed; */
    padding-bottom: 15px;
    width: 100%;
    bottom: 45%;
    display: block;
}

#flip {
    height: 65px;
    overflow: hidden;
}

#flip>div>div {
    color: #fff;
    padding: 4px 12px;
    height: 60px;
    margin-bottom: 45px;
    display: inline-block;
}

#flip div:first-child {
    animation: show 10s linear infinite;
}

#flip div div {
    background: #42c58a;
}

#flip div:first-child div {
    background: #4ec7f3;
}

#flip div:last-child div {
    background: #DC143C;
}

@keyframes show {
    0% {
        margin-top: -270px;
    }
    5% {
        margin-top: -180px;
    }
    33% {
        margin-top: -180px;
    }
    38% {
        margin-top: -90px;
    }
    66% {
        margin-top: -90px;
    }
    71% {
        margin-top: 0px;
    }
    99.99% {
        margin-top: 0px;
    }
    100% {
        margin-top: -270px;
    }
}

关于javascript - 如何在CSS中使用关键帧文本动画时设置填充文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46378426/

相关文章:

html - 转换问题 :translateX and translateY

javascript - CSS3 转换不适用于 DIV 元素

javascript - 如何在Polymer 1.0中自动对焦/自动点击纸张输入?

javascript - jquery 内容切换使用 .slideToggle()

javascript - Adobe DTM 无法将 Angular 变量识别为数据元素

JavaScript图像碰撞

javascript - 从 URL 加载数据并在 Amcharts 中绘制另一个图表

javascript - 如何根据屏幕尺寸更改 slider 和表单高度

jquery - 在 chrome 底部留下空间

jquery - Bootstrap 几个字形图标没有显示