Course Content
AJAX and jQuery Plugins
Learn how to use AJAX and plugins with jQuery to create dynamic and interactive web applications.
0/3
JQuery
About Lesson

Image Gallery using JQuery

JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Image Gallery</title>
  <style>
    .thumbnail {
      width: 100px;
      cursor: pointer;
      margin: 5px;
    }
    .enlarged {
      display: none;
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      max-width: 90%;
      max-height: 90%;
      z-index: 1000;
    }
  </style>
</head>
<body>
  <img class="thumbnail" src="image1.jpg" alt="Thumbnail 1">
  <img class="thumbnail" src="image2.jpg" alt="Thumbnail 2">
  <div id="overlay"></div>
  <img id="enlarged-image" class="enlarged" src="" alt="Enlarged Image">
  <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
  <script>
    $(document).ready(function () {
      $(".thumbnail").click(function () {
        const src = $(this).attr("src");
        $("#enlarged-image").attr("src", src).fadeIn();
      });

      $("#enlarged-image").click(function () {
        $(this).fadeOut();
      });
    });
  </script>
</body>
</html>