<html lang="en">

<head>
  <title>Home</title>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width" />
  <link rel="preconnect" href="https://fonts.googleapis.com" />
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  <link href="https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@500&display=swap" rel="stylesheet" />
  <link rel="stylesheet" href="styles.css" />
  <script type="module" src="script.js"></script>
</head>

<body>
  <main>
    <section class="thumbs"></section>
    <section class="gallery-view">
      <figure>
        <img />
        <figcaption>
          <div class="caption-text"></div>
        </figcaption>
      </figure>
    </section>
  </main>
</body>

</html>
/* resets */

figure {
  margin: 0;
}

/* layout */

body {
  width: 70%;
  max-width: 700px;

  margin: 0 auto;
}

main {
  display: flex;
}

img {
  border: 1px solid #999;
}

.thumbs img {
  display: block;
  margin: 10px;
  border-radius: 7px;
  opacity: 0.7;
}

a {
  outline: 0;
}

.thumbs a:hover img,
.thumbs a:focus img {
  opacity: 1;
}

.thumbs img:first-child {
  margin-top: 0px;
}

.gallery-view img {
  max-width: 100%;
  margin-right: 10px;
  border-radius: 7px;
}

footer,
figcaption {
  position: absolute;
  padding: 5px 10px;
  background-color: rgba(255, 255, 255, 0.5);
}

footer {
  bottom: 3px;
  left: 3px;
}

figure {
  position: relative;
}

figcaption {
  top: 0px;
  right: -2px;
  border: 1px solid #999;
  border-radius: 0 7px 0 7px;
}

/* text */

h1,
figcaption,
a {
  font-family: "Roboto Slab", serif;
}

h1 {
  text-align: center;
}

/* media queries */

@media (max-width: 980px) {
  body {
    width: 90%;
  }
}

@media (max-width: 700px) {
  body {
    width: 98%;
  }

  main {
    flex-direction: column;
  }

  .thumbs {
    display: flex;
    align-items: space-between;
    justify-content: space-between;
  }

  .thumbs img {
    margin: 0 0 10px 0;
  }
}

/* View Transitions CSS */

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.5s;
}

figcaption {
  view-transition-name: figure-caption;
}

/* Simple final style */

::view-transition-old(figure-caption),
::view-transition-new(figure-caption) {
  height: 100%;
}

/* Alternative custom animation style */

@keyframes grow-x {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

@keyframes shrink-x {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

::view-transition-old(figure-caption),
::view-transition-new(figure-caption) {
  height: auto;
  position: absolute;
  top: 0;
  right: 0;
  left: auto;
  transform-origin: right center;
}

::view-transition-old(figure-caption) {
  animation: 0.25s linear both shrink-x;
}

::view-transition-new(figure-caption) {
  animation: 0.25s 0.25s linear both grow-x;
}
console.log("Hello!");

const cdnURL = "https://cdn.glitch.global/de7f29c8-57eb-4eb1-81b5-4e0d8565ade5";

const imageData = [
  {
    name: "Jungle coast",
    file: "jungle-coast"
  },
  {
    name: "Bird in the tree",
    file: "tree-bird"
  },
  {
    name: "A view from the sky",
    file: "view-from-the-sky"
  },
  {
    name: "The view across the water",
    file: "watery-view"
  }
];

const thumbs = document.querySelector(".thumbs");
const galleryImg = document.querySelector(".gallery-view img");
const galleryCaption = document.querySelector(".gallery-view figcaption");

function init() {
  imageData.forEach((data) => {
    const img = document.createElement("img");
    const a = document.createElement("a");
    a.href = "#";
    a.title = `Click to load ${data.name} in main gallery view`;
    img.alt = data.name;
    img.src = `${cdnURL}/${data.file}_th.jpg`;
    a.appendChild(img);
    thumbs.appendChild(a);

    a.addEventListener("click", updateView);
    a.addEventListener("keypress", updateView);
  });

  galleryImg.src = `${cdnURL}/${imageData[0].file}.jpg`;
  galleryCaption.textContent = imageData[0].name;
}

function updateView(event) {
  // Handle the difference in whether the event is fired on the <a> or the <img>
  let targetIdentifier;
  if (event.target.firstChild === null) {
    targetIdentifier = event.target;
  } else {
    targetIdentifier = event.target.firstChild;
  }

  const displayNewImage = () => {
    const mainSrc = `${targetIdentifier.src.split("_th.jpg")[0]}.jpg`;
    galleryImg.src = mainSrc;
    galleryCaption.textContent = targetIdentifier.alt;
  };

  // Fallback for browsers that don't support View Transitions:
  if (!document.startViewTransition) {
    displayNewImage();
    return;
  }

  // With View Transitions:
  const transition = document.startViewTransition(() => displayNewImage());
}
init();

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.