推迟在数值范围内加载图像?

时间:2016-05-17 19:03:13

标签: javascript jquery

我有一些JS根据数值范围(例如3.png)加载图像。我想在第59帧之后推迟加载图像,直到加载前59帧之后。我怎么能做到这一点?

    for (i = 1; i < totalFrames + 1; i++) {
        var ext = '.png';
        image = new Image();

        if (isDesktop) {
            if (i % incr === 0) {
                num = i;
            }
            // Need to load these frames on desktop:
            if (
                i === 1 ||
                i === 59 ||
                i === 151 ||
                i === 256 ||
                i === 317 ||
                i === 358 ||
                i === 400
            ) {
                num = i;
            }
        } else {
            // Need to load only these frames on mobile
            if (
                (i >= 39 && i <= 59) ||
                (i >= 131 && i <= 151) ||
                (i >= 236 && i <= 256) ||
                (i >= 298 && i <= 491)
            ) {
                num = i;
            }
        }

        image.src = '/assets/images/innovation-sequence/final-stills/' + (num) + ext;
        image.setAttribute('data-num', i);
        images.push(image);
        image.onload = function() {
            loadedCount++;
            if (loadedCount < lastPng) {
                Loader.setProgress(loadedCount / lastPng);
            }
            if (parseInt(this.getAttribute('data-num'), 10) >= lastPng && !relinquished) {
                relinquished = true;
                setupLayout();
                Loader.restart();
            }
        };
    }
}

0 个答案:

没有答案