เอฟเฟกต์ Flip
องค์ประกอบหมุนรอบแกน Y 360° พร้อมแอนิเมชัน timing function ที่ซับซ้อน (ease-out → ease-in) และการย่อ-ขยายเล็กน้อย สร้าง感覺ของการพลิกบัตร 3 มิติ
โค้ดตัวอย่างสมบูรณ์
<html>
<head>
<style>
.animated {
background-image: url(/css/images/logo.png);
background-repeat: no-repeat;
background-position: left top;
padding-top: 95px;
margin-bottom: 60px;
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
@-webkit-keyframes flip {
0% { -webkit-transform: perspective(400px) rotateY(0); -webkit-animation-timing-function: ease-out; }
40% { -webkit-transform: perspective(400px) translateZ(150px) rotateY(170deg); -webkit-animation-timing-function: ease-out; }
50% { -webkit-transform: perspective(400px) translateZ(150px) rotateY(190deg) scale(1); -webkit-animation-timing-function: ease-in; }
80% { -webkit-transform: perspective(400px) rotateY(360deg) scale(0.95); -webkit-animation-timing-function: ease-in; }
100% { -webkit-transform: perspective(400px) scale(1); -webkit-animation-timing-function: ease-in; }
}
@keyframes flip {
0% { transform: perspective(400px) rotateY(0); animation-timing-function: ease-out; }
40% { transform: perspective(400px) translateZ(150px) rotateY(170deg); animation-timing-function: ease-out; }
50% { transform: perspective(400px) translateZ(150px) rotateY(190deg) scale(1); animation-timing-function: ease-in; }
80% { transform: perspective(400px) rotateY(360deg) scale(0.95); animation-timing-function: ease-in; }
100% { transform: perspective(400px) scale(1); animation-timing-function: ease-in; }
}
.flip {
-webkit-backface-visibility: visible !important;
-webkit-animation-name: flip;
backface-visibility: visible !important;
animation-name: flip;
}
</style>
</head>
<body>
<div id="animated-example" class="animated flip"></div>
<button onclick="myFunction()">Reload page</button>
<script>
function myFunction() { location.reload(); }
</script>
</body>
</html>
การวิเคราะห์ Keyframes แบบละเอียด
| % | Transform | Timing | คำอธิบาย |
|---|---|---|---|
| 0% | rotateY(0) | ease-out | เริ่มต้น หน้าบน |
| 40% | translateZ(150px) rotateY(170°) | ease-out | |
| 50% | translateZ(150px) rotateY(190°) scale(1) | ease-in | พลิกผ่าน 180° ด้านหลังขึ้น |
| 80% | rotateY(360°) scale(0.95) | ease-in | ครบรอบ ย่อเล็กน้อย |
| 100% | scale(1) | ease-in | กลับสู่ขนาดปกติ |
ความแตกต่างจาก flipIn/flipOut
- flip: หมุนครบ 360° กลับสู่สภาพเดิม
- flipInX/Y: เข้ามาจาก 90° → 0°
- flipOutX/Y: ออกจาก 0° → 90°