jquery实现页面等待加载“转圈”效果

1.js全部源码,loading.js

/**
     *  数据加载动态圈风格
     * @param property 参数对象
     *  property 参数对象详细属性设置↓
     * type (start,stop) 加载或停止转圈
     * content 加载提示内容
     * shadowColor 背景阴影颜色-建议使用带透明的颜色
     * loadingBoxColor  加载背景色
     * loadingPointColor  转圈点颜色
     * loadingContentColor  加载提示内容字体颜色
     */
      function initLoading(property) {
        $("body .loading-box-shadow-omg").remove();//清除加载图层
        if(property.type=="stop"){
            return;
        }
        var nodeHtml = '<div class="loading-box-shadow-omg"><div class="loading-box">';
        nodeHtml += '<div class="loading-circle"></div><div class="loading-content"></div></div></div>';
        $("body").append(nodeHtml);//加载布局元素
        var html = '<div style="top: 5%;left: 53%;width: 5px;height: 5px;"></div>';
        html += '<div style="top: 11%;left: 30%;width: 7px; height: 7px;"></div>';
        html += '<div style="top: 26%;left: 12%;width: 9px;height: 9px;"></div>';
        html += '<div style="top: 48%;left: 7%;width: 9px;height: 9px;"></div>';
        html += '<div style="top: 70%;left: 15%;width: 9px;height: 9px;"></div>';
        html += '<div style="top: 85%;left: 33%;width: 9px;height: 9px;"></div>';
        html += '<div style="top: 89%;left: 54%;width: 9px;height: 9px;"></div>';
        html += '<div style="top: 80%;left: 75%;width: 9px;height: 9px;"></div>';
        $("body .loading-circle").html(html);
        var content = "正在加载中...";//提示内容
        if(property.content){
            content = property.content;
        }
        $("body .loading-content").text(content);
        var shadowColor = "#211f1f5c";//阴影颜色
        if(property.shadowColor){
            shadowColor = property.shadowColor;
            $('body .loading-box-shadow-omg').css("background-color",shadowColor);
        }
        var loadingBoxColor = "white";//加载框背景色
        if(property.loadingBoxColor){
            loadingBoxColor = property.loadingBoxColor;
            $('body .loading-box-shadow-omg .loading-box').css("background-color",loadingBoxColor);
        }
        var loadingPointColor = "#292961";//动态点颜色
        if(property.loadingPointColor){
            loadingPointColor = property.loadingPointColor;
            $('body .loading-box-shadow-omg .loading-circle>div').css("background-color",loadingPointColor);
        }
        var loadingContentColor = "rebeccapurple";//提示内容颜色
        if(property.loadingContentColor){
            loadingContentColor = property.loadingContentColor;
            $('body .loading-box-shadow-omg .loading-content').css("color",loadingContentColor);
        }
    };
	initLoading({
    type:"start",
    content:"loading...",
    // shadowColor:"grey",
    // loadingBoxColor:"yellow",
    // loadingPointColor:"green",
    // loadingContentColor:"red"
});

2.css全部源码,loading.css(ps:gif图都不用找UI了,嘿嘿,不过肯定没UI的精美)

html body{
    margin: 0;
    padding: 0;
}

/*动态加载圈-loading-start*/
body .loading-box-shadow-omg{
    width: -webkit-fill-available;
    height: -webkit-fill-available;
    background-color: #211f1f5c;
    position: absolute;
    top: 0;
    z-index: 9999999;
}

.hidden{
    display: none!important;
}

body .loading-box-shadow-omg .loading-box{
    background-color: white;
    border-radius: 5px;
    position: absolute;
    top: 20%;
    left: 40%;
    width: 20%;
    height: 25%;
}

body .loading-box-shadow-omg .loading-box .loading-circle{
    width: 80px;
    height: 80px;
    background-color: transparent;
    position: absolute;
    left: 35%;
    top: 10%;
    animation: init-circle 1s linear infinite;
}

body .loading-box-shadow-omg .loading-box .loading-content{
    position: absolute;
    bottom: 5%;
    font-weight: bold;
    color: rebeccapurple;
    width: 100%;
    text-align: center;
}

body .loading-box-shadow-omg .loading-box .loading-circle>div{
    background-color: #292961;
    border-radius: 20px;
    position: absolute;
}

@keyframes init-circle {
    from{
        transform: rotate(360deg);
    }
    to{
        transform: rotate(0deg);
    }
}
/*动态加载圈-loading-stop*/

3.html全部源码,loading.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>hello</title>
    <link rel="stylesheet" href="loading.css">
</head>
<body>
</script>
</body>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="loading.js"></script>
</html>

效果图

在这里插入图片描述

4.调用initLoading方法时,可以自定义阴影遮盖颜色,转圈圈颜色等设置,属性设置方面,见js注释

initLoading({
    type:"start",
    content:"loading...",
    // shadowColor:"grey",
    // loadingBoxColor:"yellow",
    // loadingPointColor:"green",
    // loadingContentColor:"red"
});```

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值