How to create Photo Gallery on Website ?

SEO Help and Tips

How to create Photo Gallery on Website ?

Here is the code of Photo Gallery:

<head>
<style>
 .gallery-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400px;
  overflow: hidden;
  position: relative;
}

.gallery-container img {
  max-width: 100%;
  max-height: 100%;
  transition: transform 0.5s;
  cursor: pointer;
}

.preview-container {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.preview-image {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border: 1px solid #ccc;
  cursor: pointer;
  transition: transform 0.3s;
}

.preview-image:hover {
  transform: scale(1.1);
}

.button {
  background-color: #007bff;
  color: white;
  padding: 8px 16px;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  margin: 5px;
}

.button:hover {
  background-color: #0056b3;
}
</style>
</head>
<body>
<div class="gallery-container">
  <a href="image1_link_here"><img src="image1.jpg" alt="Image 1"></a>
  <a href="image2_link_here"><img src="image2.jpg" alt="Image 2"></a>
  <!-- Add more images as needed -->

  <button id="prevButton" class="button">Previous</button>
  <button id="nextButton" class="button">Next</button>
</div>
<div class="preview-container">
  <a href="image1_link_here"><img class="preview-image" src="image1.jpg" alt="Preview 1"></a>
  <a href="image2_link_here"><img class="preview-image" src="image2.jpg" alt="Preview 2"></a>
  <!-- Add more preview images as needed -->
</div>
<script>
const images = document.querySelectorAll('.gallery-container img');
const previews = document.querySelectorAll('.preview-image');
const prevButton = document.getElementById('prevButton');
const nextButton = document.getElementById('nextButton');
let currentIndex = 0;

function showImage(index) {
  images.forEach((img, i) => {
    img.style.transform = `translateY(${(i - index) * 100}px)`;
  });

  previews.forEach((preview, i) => {
    preview.style.transform = `scale(${i === index ? 1.2 : 1})`;
  });
}

prevButton.addEventListener('click', () => {
  currentIndex = (currentIndex - 1 + images.length) % images.length;
  showImage(currentIndex);
});

nextButton.addEventListener('click', () => {
  currentIndex = (currentIndex + 1) % images.length;
  showImage(currentIndex);
});

previews.forEach((preview, i) => {
  preview.addEventListener('click', () => {
    currentIndex = i;
    showImage(currentIndex);
  });
});

// Auto-move every few seconds
setInterval(() => {
  currentIndex = (currentIndex + 1) % images.length;
  showImage(currentIndex);
}, 5000); // Change the time interval as desired (in milliseconds)
</script>
</body>

Normal View:

<head>
<style>
.gallery-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400px;
  overflow: hidden;
  position: relative;
}

.gallery-container img {
  max-width: 100%;
  max-height: 100%;
  transition: transform 0.5s;
  cursor: pointer;
}

.preview-container {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.preview-image {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border: 1px solid #ccc;
  cursor: pointer;
  transition: transform 0.3s;
}

.preview-image:hover {
  transform: scale(1.1);
}

.button {
  background-color: #007bff;
  color: white;
  padding: 8px 16px;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  margin: 5px;
}

.button:hover {
  background-color: #0056b3;
}
</style>
</head>
<body>
<div class="gallery-container">
  <a href="image1_link_here"><img src="image1.jpg" alt="Image 1"></a>
  <a href="image2_link_here"><img src="image2.jpg" alt="Image 2"></a>
  <!-- Add more images as needed -->

  <button id="prevButton" class="button">Previous</button>
  <button id="nextButton" class="button">Next</button>
</div>
<div class="preview-container">
  <a href="image1_link_here"><img class="preview-image" src="image1.jpg" alt="Preview 1"></a>
  <a href="image2_link_here"><img class="preview-image" src="image2.jpg" alt="Preview 2"></a>
  <!-- Add more preview images as needed -->
</div>
<script>
const images = document.querySelectorAll('.gallery-container img');
const previews = document.querySelectorAll('.preview-image');
const prevButton = document.getElementById('prevButton');
const nextButton = document.getElementById('nextButton');
let currentIndex = 0;

function showImage(index) {
  images.forEach((img, i) => {
    img.style.transform = `translateX(${(i - index) * 100}%)`;
  });

  previews.forEach((preview, i) => {
    preview.style.transform = `scale(${i === index ? 1.2 : 1})`;
  });
}

images.forEach(img => {
  img.addEventListener('click', () => {
    img.style.transform = 'scale(2)';
  });
});

prevButton.addEventListener('click', () => {
  currentIndex = (currentIndex - 1 + images.length) % images.length;
  showImage(currentIndex);
});

nextButton.addEventListener('click', () => {
  currentIndex = (currentIndex + 1) % images.length;
  showImage(currentIndex);
});

previews.forEach((preview, i) => {
  preview.addEventListener('click', () => {
    currentIndex = i;
    showImage(currentIndex);
  });
});

// Auto-move every few seconds
setInterval(() => {
  currentIndex = (currentIndex + 1) % images.length;
  showImage(currentIndex);
}, 5000); // Change the time interval as desired (in milliseconds)
</script>
</body>



Comments

Popular posts from this blog

How to fix SSL Certificate Issues?

How to Fix Website Mixed Content Issues?

How to Fix Mobile Responsiveness Issues?

Popular posts from this blog

How to fix SSL Certificate Issues?

How to Fix Website Mixed Content Issues?

How to Fix Mobile Responsiveness Issues?