|
2 | 2 | imageGalleryOpened: false,
|
3 | 3 | imageGalleryActiveUrl: null,
|
4 | 4 | imageGalleryImageIndex: null,
|
| 5 | + imageGallery: [ |
| 6 | + { |
| 7 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-01.jpeg', |
| 8 | + 'alt': 'Photo of Mountains' |
| 9 | + }, |
| 10 | + { |
| 11 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-02.jpeg', |
| 12 | + 'alt': 'Photo of Mountains 02' |
| 13 | + }, |
| 14 | + { |
| 15 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-03.jpeg', |
| 16 | + 'alt': 'Photo of Mountains 03' |
| 17 | + }, |
| 18 | + { |
| 19 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-04.jpeg', |
| 20 | + 'alt': 'Photo of Mountains 04' |
| 21 | + }, |
| 22 | + { |
| 23 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-05.jpeg', |
| 24 | + 'alt': 'Photo of Mountains 05' |
| 25 | + }, |
| 26 | + { |
| 27 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-06.jpeg', |
| 28 | + 'alt': 'Photo of Mountains 06' |
| 29 | + }, |
| 30 | + { |
| 31 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-07.jpeg', |
| 32 | + 'alt': 'Photo of Mountains 07' |
| 33 | + }, |
| 34 | + { |
| 35 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-08.jpeg', |
| 36 | + 'alt': 'Photo of Mountains 08' |
| 37 | + }, |
| 38 | + { |
| 39 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-09.jpeg', |
| 40 | + 'alt': 'Photo of Mountains 09' |
| 41 | + }, |
| 42 | + { |
| 43 | + 'photo': 'https://cdn.devdojo.com/images/june2023/mountains-10.jpeg', |
| 44 | + 'alt': 'Photo of Mountains 10' |
| 45 | + } |
| 46 | + ], |
5 | 47 | imageGalleryOpen(event) {
|
6 | 48 | this.imageGalleryImageIndex = event.target.dataset.index;
|
7 | 49 | this.imageGalleryActiveUrl = event.target.src;
|
|
12 | 54 | setTimeout(() => this.imageGalleryActiveUrl = null, 300);
|
13 | 55 | },
|
14 | 56 | imageGalleryNext(){
|
15 |
| - if(this.imageGalleryImageIndex == this.$refs.gallery.childElementCount){ |
16 |
| - this.imageGalleryImageIndex = 1; |
17 |
| - } else { |
18 |
| - this.imageGalleryImageIndex = parseInt(this.imageGalleryImageIndex) + 1; |
19 |
| - } |
| 57 | + this.imageGalleryImageIndex = (this.imageGalleryImageIndex == this.imageGallery.length) ? 1 : (parseInt(this.imageGalleryImageIndex) + 1); |
20 | 58 | this.imageGalleryActiveUrl = this.$refs.gallery.querySelector('[data-index=\'' + this.imageGalleryImageIndex + '\']').src;
|
21 | 59 | },
|
22 | 60 | imageGalleryPrev() {
|
23 |
| - if(this.imageGalleryImageIndex == 1){ |
24 |
| - this.imageGalleryImageIndex = this.$refs.gallery.childElementCount; |
25 |
| - } else { |
26 |
| - this.imageGalleryImageIndex = parseInt(this.imageGalleryImageIndex) - 1; |
27 |
| - } |
28 |
| -
|
| 61 | + this.imageGalleryImageIndex = (this.imageGalleryImageIndex == 1) ? this.imageGallery.length : (parseInt(this.imageGalleryImageIndex) - 1); |
29 | 62 | this.imageGalleryActiveUrl = this.$refs.gallery.querySelector('[data-index=\'' + this.imageGalleryImageIndex + '\']').src;
|
30 | 63 |
|
31 | 64 | }
|
|
34 | 67 | @image-gallery-prev.window="imageGalleryPrev()"
|
35 | 68 | @keyup.right.window="imageGalleryNext();"
|
36 | 69 | @keyup.left.window="imageGalleryPrev();"
|
37 |
| - x-init=" |
38 |
| - imageGalleryPhotos = $refs.gallery.querySelectorAll('img'); |
39 |
| - for(let i=0; i<imageGalleryPhotos.length; i++){ |
40 |
| - imageGalleryPhotos[i].setAttribute('data-index', i+1); |
41 |
| - } |
42 |
| - " |
43 | 70 | class="w-full h-full select-none">
|
44 | 71 | <div class="max-w-6xl mx-auto duration-1000 delay-300 opacity-0 select-none ease animate-fade-in-view" style="translate: none; rotate: none; scale: none; opacity: 1; transform: translate(0px, 0px);">
|
45 | 72 | <ul x-ref="gallery" id="gallery" class="grid grid-cols-2 gap-5 lg:grid-cols-5">
|
46 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-01.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 01"></li> |
47 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-02.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 02"></li> |
48 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-03.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 03"></li> |
49 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-04.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 04"></li> |
50 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-05.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 05"></li> |
51 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-06.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 06"></li> |
52 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-07.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 07"></li> |
53 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-08.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 08"></li> |
54 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-09.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 09"></li> |
55 |
| - <li><img x-on:click="imageGalleryOpen" src="https://cdn.devdojo.com/images/june2023/mountains-10.jpeg" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]" alt="photo gallery image 10"></li> |
| 73 | + <template x-for="(image, index) in imageGallery"> |
| 74 | + <li><img x-on:click="imageGalleryOpen" :src="image.photo" :alt="image.alt" :data-index="index+1" class="object-cover select-none w-full h-auto bg-gray-200 rounded cursor-zoom-in aspect-[5/6] lg:aspect-[2/3] xl:aspect-[3/4]"></li> |
| 75 | + </template> |
56 | 76 | </ul>
|
57 | 77 | </div>
|
58 | 78 | <template x-teleport="body">
|
|
0 commit comments