Javascript 使用manifest,首次用户永远不会通过“progress”函数

Javascript 使用manifest,首次用户永远不会通过“progress”函数,javascript,html,html5-appcache,cache-manifest,Javascript,Html,Html5 Appcache,Cache Manifest,当我更新清单的版本时,默认页面会显示一个显示0-100%的微调器,然后会显示一条成功消息。然而,第一次使用的用户永远不会通过100%的考试。到此为止。它不执行下一个函数updateready。下面是我的代码: <script> var opts = { lines: 13, // The number of lines to draw length: 11, // The length of each line width: 5

当我更新清单的版本时,默认页面会显示一个显示0-100%的微调器,然后会显示一条成功消息。然而,第一次使用的用户永远不会通过100%的考试。到此为止。它不执行下一个函数updateready。下面是我的代码:

<script>
    var opts = {
        lines: 13, // The number of lines to draw
        length: 11, // The length of each line
        width: 5, // The line thickness
        radius: 17, // The radius of the inner circle
        corners: 1, // Corner roundness (0..1)
        rotate: 0, // The rotation offset
        color: '#FFF', // #rgb or #rrggbb
        speed: 1, // Rounds per second
        trail: 10, // Afterglow percentage
        shadow: false, // Whether to render a shadow
        hwaccel: false, // Whether to use hardware acceleration
        className: 'spinner', // The CSS class to assign to the spinner
        zIndex: 2e9, // The z-index (defaults to 2000000000)
        top: 'auto', // Top position relative to parent in px
        left: 'auto' // Left position relative to parent in px
    };
    var overlay;
    var spinner;
    var target;

    window.applicationCache.addEventListener('checking', function (event) {
        console.log("Checking for updates.");
        console.log("inside checking event, appcache status : %s", applicationCache.status);
    }, false);

    window.applicationCache.addEventListener('downloading', function (event) {
        target = document.createElement("div");
        document.body.appendChild(target);
        spinner = new Spinner(opts).spin(target);
        overlay = iosOverlay({
            text: "0%",
            spinner: spinner
        });
    }, false);

    window.applicationCache.addEventListener('progress', function (event) {
        var per = event.loaded.toString() / event.total.toString();
        var totalPercentage = Math.round(per * 100);
        Math.round
        overlay.update({
            text: totalPercentage + "%",
            spinner: spinner
        });
    }, false);

    window.applicationCache.addEventListener('updateready', function (e) {
        if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
            window.setTimeout(function () {
                overlay.update({
                    icon: "loader/img/check.png",
                    text: "Success"
                });
            }, 2e3);

            window.setTimeout(function () {
                window.location.reload();
            }, 3e3);
        }
    }, false);
</script>

我错过了“缓存”事件。当更新过程第一次完成时,即第一次保存应用程序缓存时,将执行此事件

window.applicationCache.addEventListener('cached', function (event) {
        ...
    }, false);

仅供参考,如果清单文件被更新,并且应用程序缓存被更新第二次、第三次或更多时间,也会调用此函数