当前位置:网站首页>JS progress bar, displaying the loading progress

JS progress bar, displaying the loading progress

2022-04-23 14:17:00 Ruirui junior

One : introduce 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

版权声明
本文为[Ruirui junior]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231408339096.html