Несколько уникальных изображений в частице. - PullRequest
0 голосов
/ 24 октября 2018

Я пытаюсь использовать этот частиц.js с несколькими изображениями , но я не хочу показывать один раз каждые изображения.Затем я пытаюсь записать массив, чтобы понять, но я не совсем понимаю способ его загрузки, я думаю ... Вот оригинальная часть кода, которую я пытался изменить:

/* if shape is image */

var shape_type = pJS.particles.shape.type;
if(typeof(shape_type) == 'object'){
  if(shape_type instanceof Array){
    var shape_selected = shape_type[Math.floor(Math.random() * shape_type.length)];
    this.shape = shape_selected;
  }
}else{
  this.shape = shape_type;
}

var substring = this.shape.substring(0, 5);
if(substring == 'image'){
  var sh = pJS.particles.shape;
  this.img = {
    src: sh.image.src,
    ratio: sh.image.width / sh.image.height
  }
  if(!this.img.ratio) this.img.ratio = 1;
  if(pJS.tmp.img_type == 'svg' && pJS.tmp.source_svg != undefined){
    pJS.fn.vendors.createSvgImg(this);
    if(pJS.tmp.pushing){
      this.img.loaded = false;
    }
  }
}

Но он загружает четыреслучайные изображения из моего массива, затем я хочу, чтобы каждое изображение было по одному, затем я попробовал это ...:

/* if shape is image */

var shape_type = pJS.particles.shape.type;
if(typeof(shape_type) == 'object'){
  if(shape_type instanceof Array){
    for (let index = 0; index < shape_type.length; index++) {
      console.log("test:"+shape_type[index]);
      var shape_selected = shape_type[index];
      this.shape = shape_type[index];
    }

    console.log("_shape:"+this.shape);
  }
}else{
  this.shape = shape_type;
}

var substring = this.shape.substring(0, 5);
if(substring == 'image'){
  var sh = pJS.particles.shape;
  this.img = {
    src: sh.image.src,
    ratio: sh.image.width / sh.image.height
  }
  if(!this.img.ratio) this.img.ratio = 1;
  if(pJS.tmp.img_type == 'svg' && pJS.tmp.source_svg != undefined){
    pJS.fn.vendors.createSvgImg(this);
    if(pJS.tmp.pushing){
      this.img.loaded = false;
    }
  }
}

И в консоли у меня есть:

test:image1
test:image2
test:image3
test:image4
_shape:image4
test:image1
test:image2
test:image3
test:image4
_shape:image4
test:image1
test:image2
test:image3
test:image4
_shape:image4
test:image1
test:image2
test:image3
test:image4
_shape:image4

I 'Я действительно не прав в том, как он загружается, но я не могу объяснить, почему ...

...