I am using the PhotoSwipe in my project to display Photos in a cool progressive way.
I want to iterate through a relationship between and arrangements and images. I can print out with console.log() the number of images. It works.
1 Question:
I want to dynamically fetch the count of images and display them in items:
HOW?
2 Question: How can I retrieve the dimensions of a photo dynamically, like the width and hight? I assume there might be some method like getOriginalHight()
After that I want to assign the value to w:
and h:
function showImages() {
let pswpElement = document.querySelectorAll('.pswp')[0];
// build items array
for (i = 0; i < "{{count($arrangement->images)}}"; i++) {
console.log(i);
}
let items = [
{
src: '/storage/arrangement_images/{{$arrangement->images[1]->file_name}}',
w: 500,
h: 281
},
{
src: 'https://placekitten.com/1200/900',
w: 1200,
h: 900
}
];
// define options (if needed)
let options = {
// optionName: 'option value'
// for example:
index: 0 // start at first slide
};
// Initializes and opens PhotoSwipe
let gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
}