react实现加载动画

news/2024/7/15 18:59:23 标签: react.js, 前端

1.Spinning.tsx

import "./Spinning.scss";

interface Props {
    isLoading: boolean;
    children?: React.ReactNode;
}

const Spinning: React.FC<Props> = ({
    isLoading = true,
    children
}) => {
    return <div className={`spinning-wrapper${isLoading ? " loading" : ""}`}>
        {children}
        <div className="spinning-mask">
            
            <div className="loading-spinner">
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
            </div>
        </div>
    </div>
};

export default Spinning;

2. Spinning.scss

.spinning-wrapper {
    position: relative;
    height: 100%;

    .spinning-mask {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 5;
        background: #f6f6f6ba;

        & .loading-spinner {
            width: 150px;
            height: 15px;
            margin: 0 auto;
            margin-top: 100px;

            & span {
                display: inline-block;
                width: 15px;
                height: 100%;
                margin-right: 5px;
                border-radius: 50%;
                background: #18beeb8f;
                position: relative;
                animation: load 5s ease-in-out infinite;
                -webkit-animation: load 5s ease-in-out infinite;
            }

            @keyframes load {
                0% {
                    left: -50px;
                    opacity: 0.1;
                }

                50% {
                    opacity: 1;
                }

                100% {
                    left: 100px;
                    opacity: 0.1;
                }
            }

            @-webkit-keyframes load

            /*Safari and Chrome*/
                {
                0% {
                    left: -50px;
                    opacity: 0.1;
                }

                50% {
                    opacity: 1;
                }

                100% {
                    left: 100px;
                    opacity: 0.1;
                }
            }


            & span:last-child {
                margin-right: 0px;
            }

            & span:nth-child(1) {
                -webkit-animation-delay: 0.13s;
            }

            & span:nth-child(2) {
                -webkit-animation-delay: 0.26s;
            }

            & span:nth-child(3) {
                -webkit-animation-delay: 0.39s;
            }

            & span:nth-child(4) {
                -webkit-animation-delay: 0.52s;
            }

            & span:nth-child(5) {
                -webkit-animation-delay: 0.65s;
            }

        }
    }

}

3. 调用

<Spinning isLoading={true}>
    <div>Test</div>
</Spinning>

4. 展示


http://www.niftyadmin.cn/n/5231948.html

相关文章

前端大文件上传webuploader(react + umi)

使用WebUploader还可以批量上传文件、支持缩略图等等众多参数选项可设置&#xff0c;以及多个事件方法可调用&#xff0c;你可以随心所欲的定制你要的上传组件。 分片上传 1.什么是分片上传 分片上传&#xff0c;就是将所要上传的文件&#xff0c;按照一定的大小&#xff0c;将…

力扣15题 三数之和 双指针算法

15. 三数之和 给你一个整数数组 nums &#xff0c;判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i ! j、i ! k 且 j ! k &#xff0c;同时还满足 nums[i] nums[j] nums[k] 0 。请 你返回所有和为 0 且不重复的三元组。 注意&#xff1a;答案中不可以包含重复的三…

对小程序的初了解

WXML和HTML的区别 标签名称不同 HTML&#xff1a;div、a、span、img WXML&#xff1a;view、text、image、navigator 属性节点不同 <a href"#">超链接</a> <navigator url"/pages/home/home"></navigator> 提供了类似vue的…

【图论】重庆大学图论与应用课程期末复习资料2-各章考点(填空证明部分)(私人复习资料)

图论各章考点 一、图与网络的基本概念二、树三、连通性四、路径算法五、匹配六、行遍性问题七、平面图 一、图与网络的基本概念 生成子图&#xff1a;生成子图 G ’ G’ G’中顶点个数V’必须和原图G中V的数量相同&#xff0c;而 E ’ ∈ E E’∈E E’∈E即可。顶点集导出子图…

python每日一题——18矩阵置零

题目 给定一个 m x n 的矩阵&#xff0c;如果一个元素为 0 &#xff0c;则将其所在行和列的所有元素都设为 0 。请使用 一个仅使用常量空间的原地 算法。 示例 1&#xff1a; 输入&#xff1a;matrix [[1,1,1],[1,0,1],[1,1,1]] 输出&#xff1a;[[1,0,1],[0,0,0],[1,0,1]] …

Vue系列:页面中图片等静态资源引用

前言 近期在做项目时遇到一些图片、视频、动态图片等静态资源的使用&#xff0c;在vue页面jsx、tsx中使用的时候遇到些问题&#xff1b; 对静态资源的引用使用总结如下 引入方式说明 以下代码实例以图片、vue环境为例&#xff0c;不放视屏等引入实例&#xff0c;视频使用方式…

element中el-table表头通过header-row-style设置样式

文章目录 一、知识点二、设置全部表头2.1、方式一2.2、方式二 三、设置某个表头四、最后 一、知识点 有些时候需要给element-ui表头设置不同样式&#xff0c;比如居中、背景色、字体大小等等&#xff0c;这时就可以用到本文要说的属性header-row-style。官网说明如下所示&…

TCP网络常见名词

1、MAC地址 用来识别同一链路中不同的计算机。 2、IP地址 用来识别TCP/IP网络中互连的主机和路由器。 3、端口号 用来识别同一台计算机中进行通信的不同应用程序。 1&#xff09;端口号如何确定 <1>标准既定的端口号 它是指每个应用程序都有其指定的端口号。例如…