css anminate 加载中三个点点动态出现

期待效果:

核心代码:

css3 anminate方法

css 复制代码
//html
<div>加载中<span id="dot">...</span></div>
 
//css
<style>  
#dot {
    display: inline-block;
    width: 1.5em;
    vertical-align: bottom;
    overflow: hidden;
    animation: dotting 3s infinite step-start;
}
@keyframes dotting{
    0% { width: 0; margin-right: 1.5em; }
    33% { width: .5em; margin-right: 1em; }
    66% { width: 1em; margin-right: .5em; }
    100% { width: 1.5em; margin-right: 0;}
}
</style>

一、代码实操

html代码:

html 复制代码
 <div class="contanier">
          <img
            :src="
              getAssetsFile(
                data.isFinish == 0
                  ? `smartCabin/loadingImg/isLoading_bg.png`
                  : `smartCabin/loadingImg/isErr_bg.png`
              )
            "
          />
          <div class="imgTitle">加载中<span id="dot">...</span></div>
        </div>

css:

css 复制代码
  .contanier {
    width: 50%;
    height: 80%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .imgTitle {
      font-size: calc(100vw * 18 / 1920);
      color: #757575;
      line-height: 21px;
      letter-spacing: 2px;

      #dot {
        display: inline-block;
        width: 1.5em;
        vertical-align: bottom;
        overflow: hidden;
        animation: dotting 0.5s infinite step-start;
      }
      @keyframes dotting {
        0% {
          width: 0;
          margin-right: 1.5em;
        }
        33% {
          width: 0.5em;
          margin-right: 1em;
        }
        66% {
          width: 1em;
          margin-right: 0.5em;
        }
        100% {
          width: 1.5em;
          margin-right: 0;
        }
      }
    }
    .imgTitle2 {
      .imgTitle;
      color: red;
    }

以上就是全部实现代码。。。

以下是理论知识

二、理论知识:

使用简写属性 animation 一次性设置所有动画属性,很方便。

anminate:CSS animation 属性是animation-durationhttps://developer.mozilla.org/zh-CN/docs/Web/CSS/animation-duration详情看MDN

相关推荐
渣哥14 分钟前
从 AOP 到代理:Spring 事务注解是如何生效的?
前端·javascript·面试
toobeloong29 分钟前
Electron 从低版本升级到高版本 - 开始使用@electron/remote的改造教程
前端·javascript·electron
悠哉摸鱼大王32 分钟前
前端获取设备视频流踩坑实录
前端·javascript
铅笔侠_小龙虾41 分钟前
深入理解 Vue.js 原理
前端·javascript·vue.js
西西学代码1 小时前
Flutter---showCupertinoDialog
java·前端·flutter
你的眼睛會笑1 小时前
vue3 使用html2canvas实现网页截图并下载功能 以及问题处理
前端·javascript·vue.js
ZTLJQ1 小时前
植物大战僵尸HTML5游戏完整实现教程
前端·游戏·html5
struggle20251 小时前
AxonHub 开源程序是一个现代 AI 网关系统,提供统一的 OpenAI、Anthropic 和 AI SDK 兼容 API
css·人工智能·typescript·go·shell·powershell
无光末阳1 小时前
vue 环境下多个定时器的创建与暂停的统一封装
前端·vue.js