Skip to content

Commit

Permalink
🎬 Use carousel to slide images
Browse files Browse the repository at this point in the history
  • Loading branch information
henrylee97 committed Mar 5, 2024
1 parent e864c5f commit c45ccc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
10 changes: 0 additions & 10 deletions assets/js/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,3 @@ const masonry = new Masonry(gallery, {
imagesLoaded(gallery).on('progress', function () {
masonry.layout();
});

const modals = document.getElementsByClassName('modal');
for(let i = 0; i < modals.length; i++) {
const modal = modals[i];
modal.addEventListener('show.bs.modal', event => {
const recipient = event.relatedTarget.getAttribute('data-bs-image');
const imgPlaceholder = modal.querySelector('.modal-content img');
imgPlaceholder.src = recipient;
});
}
24 changes: 21 additions & 3 deletions layouts/shortcodes/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
{{ $image = $image.Resize "1000x webp" }}
{{ end }}
<div class="item col-sm-6 col-lg-4 px-1 pb-2" data-bs-toggle="modal" data-bs-target="#{{ $name }}Modal" role="button" data-bs-image="{{ $org }}">
<div class="card">
<img src="{{ $image.RelPermalink }}" loading="lazy" class="card-img w-100">
<div data-bs-target="#{{ $name }}Carousel" data-bs-slide-to="{{ $idx }}">
<div class="card">
<img src="{{ $image.RelPermalink }}" loading="lazy" class="card-img w-100">
</div>
</div>
</div>
{{ end }}
Expand All @@ -38,7 +40,23 @@
<div class="modal-dialog modal-dialog-centered modal-xl">
<div class="modal-content bg-transparent border-0" data-bs-theme="dark">
<button type="button" class="btn-close ms-auto" data-bs-dismiss="modal" aria-label="Close"></button>
<img class="img-fluid">
<div id="{{ $name }}Carousel" class="carousel slide">
<div class="carousel-inner d-flex align-items-center">
{{ range $idx, $image := $images }}
<div class="carousel-item{{ if eq $idx 0 }} active{{ end }}">
<img src="{{ $image }}" class="d-block w-100" loading="lazy">
</div>
{{ end }}
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#{{ $name }}Carousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#{{ $name }}Carousel" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
</div>
</div>

0 comments on commit c45ccc4

Please sign in to comment.