From d99394dd1f731b87e22bbd3d6ff81b6eb7025e6f Mon Sep 17 00:00:00 2001 From: Valik Date: Mon, 6 Nov 2023 15:59:46 +0100 Subject: [PATCH] Included the `SimpleLightbox` library --- 01-gallery.html | 2 ++ 02-lightbox.html | 21 +++++++++++++++++++++ js/01-gallery.js | 1 - js/02-lightbox.js | 37 ++++++++++++++++++++++++++++++++++--- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/01-gallery.html b/01-gallery.html index ffe78e1..1a13d42 100644 --- a/01-gallery.html +++ b/01-gallery.html @@ -66,7 +66,9 @@

Image Gallery

+ + diff --git a/02-lightbox.html b/02-lightbox.html index 4f568cf..232e579 100644 --- a/02-lightbox.html +++ b/02-lightbox.html @@ -31,6 +31,16 @@ SimpleLightbox library + + + + @@ -54,9 +64,20 @@ >

+

SimpleLightbox Gallery

+ + + + + diff --git a/js/01-gallery.js b/js/01-gallery.js index 01a2cf0..3d4bce2 100644 --- a/js/01-gallery.js +++ b/js/01-gallery.js @@ -1,5 +1,4 @@ import { galleryItems } from "./gallery-items.js"; -// Change code below this line // Create Gallery const galleryContainer = document.querySelector(".gallery"); diff --git a/js/02-lightbox.js b/js/02-lightbox.js index 5a01ac2..08d38d3 100644 --- a/js/02-lightbox.js +++ b/js/02-lightbox.js @@ -1,4 +1,35 @@ -import { galleryItems } from './gallery-items.js'; -// Change code below this line +import { galleryItems } from "./gallery-items.js"; -console.log(galleryItems); +// Create Gallery +const galleryContainer = document.querySelector(".gallery"); + +const galleryImage = galleryItems.map((element) => { + const galleryItem = document.createElement("li"); + galleryItem.classList.add("gallery__item"); + + const galleryLink = document.createElement("a"); + galleryLink.classList.add("galery__link"); + galleryLink.href = element.original; + + const image = document.createElement("img"); + image.classList.add("gallery__image"); + image.src = element.preview; + image.alt = element.description; + // image.dataset.source = element.original; + + galleryLink.appendChild(image); + galleryItem.appendChild(galleryLink); + + return galleryItem; +}); + +galleryContainer.append(...galleryImage); + +// Initialization of SimpleLightbox +const gallery = new SimpleLightbox(".gallery a", { + captions: true, + captionsData: "alt", + captionDelay: 250, + animationSpeed: 100, + fadeSpeed: 150, +});