CSS Animation GalleryCSS, JavaScript
👤 Sharing: AI
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Animation Gallery</title>
<style>
body {
font-family: sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
.gallery-container {
max-width: 960px;
margin: 20px auto;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.gallery-item {
position: relative;
overflow: hidden;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
.gallery-item img {
width: 100%;
height: auto;
display: block;
transition: transform 0.3s ease;
}
.gallery-item:hover img {
transform: scale(1.1);
}
.animation-type {
position: absolute;
top: 10px;
left: 10px;
background-color: rgba(0, 0, 0, 0.7);
color: #fff;
padding: 5px 10px;
border-radius: 5px;
font-size: 0.8em;
z-index: 1;
}
/* Animation Styles */
.fade-in img {
animation: fadeIn 1s ease-in-out;
}
.slide-up img {
animation: slideUp 0.8s ease-out;
}
.zoom-in img {
animation: zoomIn 0.6s ease-in-out;
}
.rotate img {
animation: rotate 1s linear;
}
/* Keyframes */
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slideUp {
from { transform: translateY(50px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
@keyframes zoomIn {
from { transform: scale(0); }
to { transform: scale(1); }
}
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
/* Responsive Design */
@media (max-width: 600px) {
.gallery-container {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="gallery-container">
<div class="gallery-item fade-in">
<span class="animation-type">Fade In</span>
<img src="https://via.placeholder.com/300/007bff" alt="Image 1">
</div>
<div class="gallery-item slide-up">
<span class="animation-type">Slide Up</span>
<img src="https://via.placeholder.com/300/dc3545" alt="Image 2">
</div>
<div class="gallery-item zoom-in">
<span class="animation-type">Zoom In</span>
<img src="https://via.placeholder.com/300/28a745" alt="Image 3">
</div>
<div class="gallery-item rotate">
<span class="animation-type">Rotate</span>
<img src="https://via.placeholder.com/300/ffc107" alt="Image 4">
</div>
<div class="gallery-item fade-in">
<span class="animation-type">Fade In</span>
<img src="https://via.placeholder.com/300/17a2b8" alt="Image 5">
</div>
<div class="gallery-item slide-up">
<span class="animation-type">Slide Up</span>
<img src="https://via.placeholder.com/300/6c757d" alt="Image 6">
</div>
<div class="gallery-item zoom-in">
<span class="animation-type">Zoom In</span>
<img src="https://via.placeholder.com/300/343a40" alt="Image 7">
</div>
<div class="gallery-item rotate">
<span class="animation-type">Rotate</span>
<img src="https://via.placeholder.com/300/007bff" alt="Image 8">
</div>
</div>
<script>
// JavaScript for potential interactivity or dynamic content
// (Example: Add more images dynamically)
// Function to add a new gallery item
function addGalleryItem(animationClass, imageUrl, altText, animationType) {
const galleryContainer = document.querySelector('.gallery-container');
const newGalleryItem = document.createElement('div');
newGalleryItem.classList.add('gallery-item', animationClass);
const animationTypeSpan = document.createElement('span');
animationTypeSpan.classList.add('animation-type');
animationTypeSpan.textContent = animationType;
const imageElement = document.createElement('img');
imageElement.src = imageUrl;
imageElement.alt = altText;
newGalleryItem.appendChild(animationTypeSpan);
newGalleryItem.appendChild(imageElement);
galleryContainer.appendChild(newGalleryItem);
}
// Example usage (add a new image with the fade-in animation)
// addGalleryItem('fade-in', 'https://via.placeholder.com/300/f0f0f0', 'New Image', 'Fade In');
</script>
</body>
</html>
```
👁️ Viewed: 24
Comments