คุณสมบัติ animationName ใช้สำหรับรับหรือตั้งชื่อแอนิเมชั่นสำหรับการอ้างอิงของ @keyframes
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์สำหรับ −
การตั้งค่าคุณสมบัติ animationName -
object.style.animationName = "none|keyframename|initial|inherit"
คุณค่า
ต่อไปนี้เป็นค่า -
| Sr.No | ค่า &คำอธิบาย |
|---|---|
| 1 | ไม่มี เป็นค่าเริ่มต้นที่ระบุว่าจะไม่มีภาพเคลื่อนไหว |
| 2 | ชื่อเฟรมหลัก เพื่อระบุชื่อคีย์เฟรมที่จะผูกตัวเลือก |
| 3 | ค่าเริ่มต้น สำหรับการตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| 4 | สืบทอด เพื่อสืบทอดค่าคุณสมบัติหลัก |
ตัวอย่าง
ให้เราดูตัวอย่างคุณสมบัติ animationName -
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 60px;
height: 40px;
border: 10px groove fuchsia;
position: relative;
animation-name: bravo;
animation-iteration-count:infinite;
animation-duration: 5s;
}
@keyframes bravo {
from {left: 0px; }
to {left: 600px;}
}
@keyframes NEW_FRAME {
from {left:550px; }
to {left: 0px;}
}
</style>
<script>
function nameChange(){
document.getElementById("DIV1").style.animationName="NEW_FRAME";
document.getElementById("Sample").innerHTML="The animation name is now NEW_FRAME";
}
</script>
</head>
<body>
<div id="DIV1">SAMPLE TEXT</div>
<p>Click the below button to change the above animation fillmode property</p>
<button onclick="nameChange()">CHANGE NAME</button>
<p id="Sample"></p>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ ภาพเคลื่อนไหวเคลื่อนจากซ้ายไปขวา −

เมื่อคลิกปุ่ม CHANGE NAME ภาพเคลื่อนไหวจะย้ายจากซ้ายไปขวา -
