ใช้คุณสมบัติ transform ใน JavaScript เพื่อตั้งค่าการแปลงรูป 2D หรือ 3D ให้กับองค์ประกอบ ตั้งค่าเป็น rotate (60deg) หากต้องการหมุน 60 องศา เป็นต้น
ตัวอย่าง
คุณสามารถลองรันโค้ดต่อไปนี้เพื่อนำการแปลงรูป 2D หรือ 3D ไปใช้กับองค์ประกอบด้วย JavaScript −
<!DOCTYPE html> <html> <head> <style> #box { margin-left: 20px; border: 2px solid black; width: 300px; height: 250px; background-color: gray; color: white; } </style> </head> <body> <button onclick = "display()">Apply</button> <div id = "box"><p>Demo Text</p></div> <script> function display() { document.getElementById("box").style.transform = "rotate(60deg)"; } </script> </body> </html>