Vue3 首屏渲染 loading动画效果

index.html

  <body>
    <noscript>
      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app">
      <style>
        .app-loading {
          display: flex;
          width: 100%;
          height: 100%;
          justify-content: center;
          align-items: center;
          flex-direction: column;
          background-color: #f4f7f9;
        }

        .app-loading .app-loading-wrap {
          position: absolute;
          top: 48%;
          left: 50%;
          display: flex;
          -webkit-transform: translate3d(-50%, -50%, 0);
          transform: translate3d(-50%, -50%, 0);
          justify-content: center;
          align-items: center;
          flex-direction: column;
        }

        .app-loading .dots {
          display: flex;
          padding: 98px;
          justify-content: center;
          align-items: center;
        }

        .app-loading .app-loading-title {
          display: flex;
          margin-top: 30px;
          font-size: 26px;
          font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
          color: rgba(0, 0, 0, 0.9);
          justify-content: center;
          align-items: center;
        }

        .app-loading .app-loading-logo {
          width: 30px;
          margin-right: 20px;
        }

        .dot {
          position: relative;
          display: inline-block;
          width: 48px;
          height: 48px;
          margin-top: 30px;
          font-size: 32px;
          transform: rotate(45deg);
          box-sizing: border-box;
          animation: antRotate 1.2s infinite linear;
        }

        .dot i {
          position: absolute;
          display: block;
          width: 20px;
          height: 20px;
          background-color: #3B27B8;
          border-radius: 100%;
          opacity: 0.3;
          transform: scale(0.75);
          animation: antSpinMove 1s infinite linear alternate;
          transform-origin: 50% 50%;
        }

        .dot i:nth-child(1) {
          top: 0;
          left: 0;
        }

        .dot i:nth-child(2) {
          top: 0;
          right: 0;
          -webkit-animation-delay: 0.4s;
          animation-delay: 0.4s;
        }

        .dot i:nth-child(3) {
          right: 0;
          bottom: 0;
          -webkit-animation-delay: 0.8s;
          animation-delay: 0.8s;
        }

        .dot i:nth-child(4) {
          bottom: 0;
          left: 0;
          -webkit-animation-delay: 1.2s;
          animation-delay: 1.2s;
        }
        @keyframes antRotate {
          to {
            -webkit-transform: rotate(405deg);
            transform: rotate(405deg);
          }
        }
        @-webkit-keyframes antRotate {
          to {
            -webkit-transform: rotate(405deg);
            transform: rotate(405deg);
          }
        }
        @keyframes antSpinMove {
          to {
            opacity: 1;
          }
        }
        @-webkit-keyframes antSpinMove {
          to {
            opacity: 1;
          }
        }
      </style>
      <div class="app-loading">
        <div class="app-loading-wrap">
          <div class="app-loading-dots">
            <span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
          </div>
          <div class="app-loading-title">
            <img src="<%= BASE_URL %>favicon.ico" class="app-loading-logo" alt="Logo" />
            <span><%= htmlWebpackPlugin.options.title %></span>
          </div>
        </div>
      </div>
    </div>
    <!-- built files will be auto injected -->
  </body>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这里是一个简单的Vue请求加载动画代码示例: ``` <template> <div> <div v-if="loading" class="loading-overlay"> <div class="loading-spinner"></div> </div> <div v-else> <!-- Your content goes here --> </div> </div> </template> <script> export default { data() { return { loading: false, }; }, methods: { async fetchData() { this.loading = true; // Your API request goes here const response = await fetch('https://jsonplaceholder.typicode.com/todos/1'); const data = await response.json(); this.loading = false; // Do something with the response data console.log(data); }, }, mounted() { this.fetchData(); }, }; </script> <style> .loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; justify-content: center; align-items: center; } .loading-spinner { border: 16px solid #f3f3f3; border-top: 16px solid #3498db; border-radius: 50%; width: 120px; height: 120px; animation: spin 2s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } </style> ``` 这个代码使用了一个布尔值 `loading` 来控制加载动画的显示和隐藏。在组件的 `fetchData` 方法中,我们首先将 `loading` 设置为 `true`,然后发起一个异步请求。请求完成后,我们将 `loading` 设置为 `false`,并在控制台输出响应数据。 在模板中,我们使用 `v-if` 条件渲染来控制加载动画的显示和隐藏。如果 `loading` 为 `true`,则显示一个半透明的遮罩层和一个旋转的加载动画;否则,显示实际的内容。 在样式中,我们定义了一个 `loading-overlay` 类来控制遮罩层的样式,以及一个 `loading-spinner` 类来控制加载动画的样式。加载动画使用了 CSS3 动画来实现旋转效果

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值