lightswind
Version:
A modern frontend library with pre-built Tailwind CSS components for building responsive and interactive user interfaces.
110 lines (93 loc) • 5.89 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Image Gallery</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightwind@3.0.0/src/lightswind.css">
<style>
.InterativeGalleryCard:hover {
transform: perspective(1000px);
}
.InterativeGalleryCard {
transition: transform 0.2s ease, box-shadow 0.2s ease;
will-change: transform;
}
</style>
</head>
<body class="bg-gray-100 dark:bg-black transition-colors duration-300">
<div class="bg-gray-100 dark:bg-black transition-colors duration-300 w-full">
<div class="container mx-auto py-10 font-primarylw mt-4">
<h1 class="text-3xl font-bold text-center mb-8 text-gray-900 dark:text-white">Interactive Image Gallery</h1>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<div class="InterativeGalleryCard relative overflow-hidden rounded-lg">
<img class="w-full h-full object-cover rounded-lg"
src="https://images.pexels.com/photos/10643964/pexels-photo-10643964.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
alt="Image 1">
</div>
<div class="InterativeGalleryCard relative overflow-hidden rounded-lg">
<img class="w-full h-full object-cover rounded-lg"
src="https://images.pexels.com/photos/27578999/pexels-photo-27578999/free-photo-of-3d-render.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
alt="Image 2">
</div>
<div class="InterativeGalleryCard relative overflow-hidden rounded-lg">
<img class="w-full h-full object-cover rounded-lg"
src="https://images.pexels.com/photos/11643390/pexels-photo-11643390.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
alt="Image 3">
</div>
<div class="InterativeGalleryCard relative overflow-hidden rounded-lg">
<img class="w-full h-full object-cover rounded-lg"
src="https://images.pexels.com/photos/18108322/pexels-photo-18108322/free-photo-of-3d-3d-render.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
alt="Image 4">
</div>
<div class="InterativeGalleryCard relative overflow-hidden rounded-lg">
<img class="w-full h-full object-cover rounded-lg"
src="https://images.pexels.com/photos/325044/pexels-photo-325044.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
alt="Image 5">
</div>
<div class="InterativeGalleryCard relative overflow-hidden rounded-lg">
<img class="w-full h-full object-cover rounded-lg"
src="https://images.pexels.com/photos/1270184/pexels-photo-1270184.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
alt="Image 6">
</div>
<div class="InterativeGalleryCard relative overflow-hidden rounded-lg">
<img class="w-full h-full object-cover rounded-lg"
src="https://images.pexels.com/photos/33045/lion-wild-africa-african.jpg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
alt="Image 7">
</div>
<div class="InterativeGalleryCard relative overflow-hidden rounded-lg">
<img class="w-full h-full object-cover rounded-lg"
src="https://images.pexels.com/photos/937980/pexels-photo-937980.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
alt="Image 8">
</div>
</div>
</div>
</div>
<script>
// Select all the InterativeGalleryCards
const InterativeGalleryCards = document.querySelectorAll('.InterativeGalleryCard');
InterativeGalleryCards.forEach(InterativeGalleryCard => {
InterativeGalleryCard.addEventListener('mousemove', (e) => {
const InterativeGalleryCardRect = InterativeGalleryCard.getBoundingClientRect();
const InterativeGalleryCardWidth = InterativeGalleryCardRect.width;
const InterativeGalleryCardHeight = InterativeGalleryCardRect.height;
// Get the position of the mouse relative to the center of the InterativeGalleryCard
const centerX = InterativeGalleryCardRect.left + InterativeGalleryCardWidth / 2;
const centerY = InterativeGalleryCardRect.top + InterativeGalleryCardHeight / 2;
const mouseX = e.clientX - centerX;
const mouseY = e.clientY - centerY;
// Calculate rotation angles
const rotateX = (mouseY / InterativeGalleryCardHeight) * 100; // Max 15 degrees
const rotateY = (mouseX / InterativeGalleryCardWidth) * -100; // Max -15 degrees
// Apply the rotation to the InterativeGalleryCard
InterativeGalleryCard.style.transform = 'perspective(1000px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)';
});
InterativeGalleryCard.addEventListener('mouseleave', () => {
// Reset the rotation when the mouse leaves
InterativeGalleryCard.style.transform = 'perspective(1000px) rotateX(0) rotateY(0)';
});
});
</script>
</body>
</html>