通過sonic.js寫一個(gè)簡單的loading

<!doctype html>
<meta charset="utf-8" />
<title>Sonic</title>

<style>

body {
    background: #222;
    color: #FFF;
    text-align: center;
    font-family: sans-serif;
    font-size: .8em;
    width:100%;
    height:100%;
}

#container {
    overflow: hidden;
    padding: 20px;
    width: 100%;
    height:100%;
    margin: 0 auto;
    position: fixed;
    top:0;
    left:0;
    z-index: 100;
}

#in { 
    overflow: hidden;
}

a { color: #FFF; }

div.l {
    float: left;
    margin: 20px 20px 0 0;
    height: 150px;
    width: 150px;
    position: relative;
}
canvas { display: block; background-color: white;width: 100%;
    height:100%;}
    #a{
        position: relative;
        z-index: 10;
    }
</style>

<body>

<div id="container">


<div id="in"></div>

</div>
<div id="a">

</div>
<script src="../src/sonic.js"></script>
<script>

var loaders = [
    {

        width: 100,
        height: 100,

        stepsPerFrame: 1,
        trailLength: 1,
        pointDistance: .02,
        fps: 30,

        fillColor: '#05E2FF',

        step: function(point, index) {
            
            this._.beginPath();
            this._.moveTo(point.x, point.y);
            this._.arc(point.x, point.y, index * 7, 0, Math.PI*2, false);
            this._.closePath();
            this._.fill();

        },

        path: [
            ['arc', 50, 50, 30, 0, 360]
        ]

    }
];

var d, a, container = document.getElementById('in');
var imgArr = document.getElementById("a");

for (var i = -1, l = loaders.length; ++i < l;) {
    
    d = document.createElement('div');
    d.className = 'l';

    a = new Sonic(loaders[i]);

    d.appendChild(a.canvas);
    container.appendChild(d);
    a.play();
}

</script>
<script>

        var arrImgs = [
              "",
                "",
                "",
                ""
        ];
        var loadNum = 0;
        for (var i = 0;i < arrImgs.length;i++) {
            var img = new Image();
            img.src = arrImgs[i];
            img.onload = function (data) {
                loadNum++;
                imgArr.append(data);
                if (loadNum == arrImgs.length) {
                    setTimeout(function () {
//                        d.style.display = 'none';
                    },1000)
                }
            }(img)
        }
</script>

</body>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容