基于cTask实现的预加载演示

    cTask
        .timeout(10000) // 超时延迟时间
        .extra(2) // 额外的外链js数
        .init([ // 预加载任务列表
            function(){ // 方法
                console.log("first task")
            },
            "http://imgcache.gtimg.cn/mediastyle/mobile/event/20150615_fatherday_card/img/template_pic_1.jpg", // 图片
            "http://imgcache.gtimg.cn/mediastyle/mobile/event/20150615_fatherday_card/img/template_pic_2.jpg",
            "http://imgcache.gtimg.cn/mediastyle/mobile/event/20150615_fatherday_card/img/template_pic_3.jpg",
            "http://i.gtimg.cn/music/photo_new/T010M000003rFNYM4Guvii.jpg?max_age=2592000",
            "http://imgcache.gtimg.cn/mediastyle/mobile/event/20151221_personal_inventory/img/profile_bg.jpg?max_age=2592000",
            { // 图片
                type: "image",
                src: "http://imgcache.gtimg.cn/mediastyle/mobile/event/20150615_fatherday_card/img/template_pic_4.jpg"
            },
            { // js
                type: "script",
                src: "http://imgcache.gtimg.cn/music/h5/client/profile/echarts.js?max_age=604800"
            },
            function(){
                console.log("last task")
            }
        ])
        .then(function(percent){
            console.log("已加载: " + percent);

            // 更新加载进度条
            var p = 50 * (1 - percent);
            progress.style.transform = progress.style["-webkit-transform"] = "translateY(" + p + "%)";
        })
        .finish(function(error){
            // 超时或加载完成
            console.log("加载完成 " + (error || ""));

            // 隐藏加载进度条
            setTimeout(function(){
                loading.style.display = "none";
            }, 300);

            // 页面初始化
            initPage();
        });
    
正在加载中...