CSS 怎么实现 微信输入法进度条按钮效果?

微信输入法这种进度条效果的按钮怎么用 CSS 实现
image.png

阅读 2k
3 个回答

linear-gradient + background-position + background-clip

兼容性可能不太好

Peek 2024-01-23 16-38.gif

Codepen


简单粗暴的方法就是两个文字叠加,一个文字放在进度条里面,然后进度条滚动过去之后就显示出来。

粗糙的代码大概就是这样:

<div>
   <strong>正在安装...</strong>
   <span><em>正在安装...</em></span>
</div>
div {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    width: 200px;
    height: 30px;
    overflow: hidden;
    border-radius: 8px;
    background-color: #ceeee4;
}
span {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 50%;
    overflow: hidden;
    background-color: #25cb93;
    animation: loading 4s 0.5s infinite ease-in-out;
}
em {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 30px;
    font-style: normal;
    font-weight: normal;
    font-size: 16px;
    color: #fff;
}
strong {
    position: relative;
    font-size: 16px;
    color: #25cb93;
}
@keyframes loading {
    0% {
        width: 1%;
    }
    100% {
        width: 100%;
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题