ใช้ CSS transform: scaleX(-1) กลับภาพแนวนอน (Mirror Effect) เมื่อ Hover
ตัวอย่างโค้ด
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> img:hover { transform: scaleX(-1); width: 400; height: 400; } </style> </head> <body> <h1>Flipping an Image Example</h1> <img src="https://i.picsum.photos/id/551/400/400.jpg"> <h1>Hover over the above image to see it mirrored</h1> </body> </html>
Transform Functions สำหรับ Flip
| Transform | ผลลัพธ์ |
|---|---|
scaleX(-1) | พลิกแนวนอน (Mirror Horizontal) |
scaleY(-1) | พลิกแนวตั้ง (Mirror Vertical) |
scale(-1, -1) หรือ rotate(180deg) | พลิกทั้งสองด้าน (หมุน 180°) |