当前位置:网站首页>js 进度条,显示加载进度

js 进度条,显示加载进度

2022-04-23 14:09:00 瑞瑞小同学

一:引入ImgPreloader.js

(function() {

  function Preloader(srcs, opts) {
    this.srcs = srcs;
    this.opts = opts ||{};
    this.loaded = [];
    this.load();
  }

  Preloader.prototype.load = function() {
    for (var i = 0; i < this.srcs.length; ++i) {
      var src = this.srcs[i];
      this.loadImg(src);
    }
  };


  Preloader.prototype.loadImg = function(src) {
    var that = this;
    var img = new Image();
    img.onload = function() {
      that.onload(img);
    };
    img.src = src;
  };

  Preloader.prototype.onload = function(obj) {
    this.loaded.push(obj);
    if (this.opts.each instanceof Function) {
      var percent = this.loaded.length / this.srcs.length;
      this.o

版权声明
本文为[瑞瑞小同学]所创,转载请带上原文链接,感谢
https://blog.csdn.net/yr123456654321/article/details/113121273