Simple Fotorama image array

303 Views Asked by At

I'm trying to display 80 images from a folder by using Javascript Fotorama image gallery.

Instead of writing each image directory is there any way to display them all by using an array? Need to display images from 1 to 80.

Image names will stay the same for example - image_1.jpeg, image_2.jpeg, etc

<script>
  $('.fotorama').fotorama({
    data: [
      {img: 'img/slides/image_1.jpeg'},
      {img: 'img/slides/image_2.jpeg'},
      {img: 'img/slides/image_3.jpeg'}
    ]
  });
</script>
1

There are 1 best solutions below

0
user7290573 On

A simple for loop will do it. Create your array like so:

var images = [];

for (var i = 1; i <= 80; i++) {
    images.push({img: 'img/slides/image_' + i + '.jpeg'});
}

console.log(images);

Then pass to fotorama:

$('.fotorama').fotorama({
    data: images
});