首页 > 移动平台 > 详细

[React] Delay the Appearance of a Loading Spinner with CSS in React

时间:2020-04-20 10:17:12      阅读:77      评论:0      收藏:0      [点我收藏+]

Eager delay spinners are not a good user experience.
They can make a snappy user interface feel slower.

We want delay spinners to appear only after a perceivable delay.
useTransition doesn‘t yet have an API for customizing this.
Until it does, we can use CSS animations to delay visibility of delay spinners.

 

import React from "react";

export function DelaySpinner() {
  return (
    <span role="img" aria-label="spinner" className="DelaySpinner">
      <style>{`
        .DelaySpinner {
          {/* apply two animation at the same time,
            0s linear 0.5s forwards makeVisible: start immedicatly, wait for 0.5s
          */}
          animation: 0s linear 0.5s forwards makeVisible, rotation 1.5s infinite linear;
          display: inline-block;
          font-size: .7rem;
          visibility: hidden;
        }

        @keyframes rotation {
          from { transform: rotate(0deg) }
          to { transform: rotate(359deg) }
        }

        @keyframes makeVisible {
          to {
            visibility: visible;
          }
        }
      `}</style>
      ??
    </span>
  );
}

 

[React] Delay the Appearance of a Loading Spinner with CSS in React

原文:https://www.cnblogs.com/Answer1215/p/12735454.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!