body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.card {
width: 300px;
height: 400px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
transition: transform 0.5s ease;
}
.card:hover {
transform: rotateY(20deg) rotateX(20deg);
}
const card = document.querySelector(‘.card’);
card.addEventListener(‘mousemove’, (e) => {
const xAxis = (window.innerWidth / 2 – e.pageX) / 25;
const yAxis = (window.innerHeight / 2 – e.pageY) / 25;
card.style.transform = `rotateY(${xAxis}deg) rotateX(${yAxis}deg)`;
});
card.addEventListener(‘mouseenter’, () => {
card.style.transition = ‘none’;
});
card.addEventListener(‘mouseleave’, () => {
card.style.transition = ‘transform 0.5s ease’;
card.style.transform = ‘rotateY(0deg) rotateX(0deg)’;
});