สร้างเอฟเฟกต์ Overlay สไลด์ขึ้นจากด้านล่าง (Bottom Slide Up) ครอบคลุมรูปภาพเมื่อ Hover ใช้ bottom: 100% -> 0 และ height: 0 -> 100%
ตัวอย่างโค้ด
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .card-container { position: relative; width: 50%; } img { display: block; width: 100%; } .overlay { position: absolute; bottom: 100%; background-color: rgb(55, 74, 179); overflow: hidden; width: 100%; height: 0; transition: .5s ease-in-out; } .card-container:hover .overlay { bottom: 0; height: 100%; } .caption { color: white; font-size: 30px; position: absolute; top: 50%; left: 50%; text-align: center; } </style> </head> <body> <h1>Image Overlay Slide Example</h1> <div class="card-container"> <img src="https://i.picsum.photos/id/237/536/354.jpg"> <div class="overlay"> <div class="caption">Dog</div> </div> </div> </body> </html>
ความแตกต่างจาก Zoom Effect
| Zoom Effect | Slide Effect |
|---|---|
| transform: scale(0) -> scale(1) | bottom: 100% -> 0; height: 0 -> 100% |
| ขยายจากจุดกึ่งกลาง | สไลด์ขึ้นจากด้านล่าง |
| Overlay อยู่กึ่งกลางแล้วหด | Overlay เริ่มต้นอยู่นอกจอ (bottom: 100%) |
การทำงาน
- ปกติ:
bottom: 100%; height: 0;- Overlay อยู่ข้างนอกรูป (ด้านล่าง) ความสูง 0 - Hover:
bottom: 0; height: 100%;- Overlay ขยับขึ้นมาติดขอบล่าง และขยายสูงเต็มรูป - Transition ทำให้สไลด์ขึ้นมาสลม
ผลลัพธ์
รูปสุนัข Hover -> แถบสีน้ำเงินสไลด์ขึ้นจากล่างครอบทั้งรูป แสดง "Dog" ตรงกลาง