Hover effektek
Élő 3D döntés
Élő előnézet – az animáció teljes méretben.
Élő előnézet
HTML · CSS · JS
<div class="we-hover-tilt">
<div class="we-tilt-glow"></div>
<span class="we-tilt-label">
WebElements
</span>
<strong>
Élő perspektíva
</strong>
<small>
Mozgasd fölötte az egeret
</small>
</div>
.we-hover-tilt {
width: 100%;
max-width: 440px;
height: 190px;
margin: 60px auto;
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: center;
padding: 35px 40px;
box-sizing: border-box;
background:
linear-gradient(
135deg,
#0b1014,
#101a1d
);
border: 1px solid rgba(142,232,212,.25);
border-radius: 18px;
color: #f2f4f0;
font-family: Arial, sans-serif;
transform-style: preserve-3d;
perspective: 1000px;
transition:
transform .15s ease-out,
box-shadow .35s ease,
border-color .35s ease;
will-change: transform;
}
.we-hover-tilt:hover {
border-color: rgba(142,232,212,.65);
box-shadow:
0 25px 55px rgba(0,0,0,.5),
0 0 35px rgba(142,232,212,.10);
}
.we-tilt-glow {
position: absolute;
width: 180px;
height: 180px;
left: var(--glow-x, 50%);
top: var(--glow-y, 50%);
transform: translate(-50%, -50%);
background:
radial-gradient(
circle,
rgba(142,232,212,.22),
rgba(142,232,212,.07) 35%,
transparent 70%
);
pointer-events: none;
opacity: 0;
transition:
opacity .3s ease,
left .08s linear,
top .08s linear;
}
.we-hover-tilt:hover .we-tilt-glow {
opacity: 1;
}
.we-tilt-label,
.we-hover-tilt strong,
.we-hover-tilt small {
position: relative;
z-index: 2;
transform: translateZ(35px);
}
.we-tilt-label {
margin-bottom: 12px;
font-size: 11px;
letter-spacing: 4px;
text-transform: uppercase;
color: #8ee8d4;
}
.we-hover-tilt strong {
font-size: 27px;
font-weight: 500;
}
.we-hover-tilt small {
margin-top: 10px;
font-size: 13px;
color: rgba(242,244,240,.62);
}
const tiltCard = document.querySelector('.we-hover-tilt');
tiltCard.addEventListener('mousemove', function(e) {
const rect = this.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const rotateY = ((x - centerX) / centerX) * 8;
const rotateX = ((centerY - y) / centerY) * 8;
const glowX = (x / rect.width) * 100;
const glowY = (y / rect.height) * 100;
this.style.transform =
`perspective(1000px)
rotateX(${rotateX}deg)
rotateY(${rotateY}deg)
translateY(-5px)`;
this.style.setProperty('--glow-x', glowX + '%');
this.style.setProperty('--glow-y', glowY + '%');
});
tiltCard.addEventListener('mouseleave', function() {
this.style.transform =
'perspective(1000px) rotateX(0deg) rotateY(0deg) translateY(0)';
});