分时函数

分时创建DDOM节点函数

 var arr = [];
        for (var i = 1; i <= 32524; i++) {
            arr.push(i) 
        }
        var timeChunk = function (arr, fn, count) {
            var obj, t;
            var len = arr.length;
            var start = function () {
                for (var i = 0; i < Math.min(count || 1, len); i++) {
                    var obj = arr.shift();
                    fn(obj)
                }
            };
            return function () {
                t = setInterval(function () {
                    if (len === 0) {
                        return clearInterval(t);
                    }
                    start() //开始
                }, 200)
            }
        }

        var renderFriendList = timeChunk(arr, function (obj) {
            var div = document.createElement('div');
            div.innerHTML = obj;
            document.body.appendChild(div)
        },3)

        renderFriendList();

© 版权声明
THE END
喜欢就支持以下吧
点赞3
分享
评论 抢沙发