Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

คุณสมบัติ HTML DOM Style animationPlayState


คุณสมบัติ animationPlayState ใช้สำหรับตั้งค่าหรือรับค่าสถานะของอนิเมชัน ว่ากำลังทำงาน (running) หรือหยุดชั่วคราว (paused) สามารถใช้สลับสถานะอนิเมชันได้

ไวยากรณ์ (Syntax)

object.style.animationPlayState = "running|paused|initial|inherit"

ค่าที่ใช้ได้ (Values)

ลำดับ ค่าและคำอธิบาย
1 running
ระบุว่าอนิเมชันกำลังทำงานอยู่ เป็นค่าเริ่มต้น
2 paused
ระบุว่าอนิเมชันถูกหยุดชั่วคราว
3 initial
ตั้งค่าคุณสมบัติให้เป็นค่าเริ่มต้น
4 inherit
สืบทอดคุณสมบัตินี้จากองค์ประกอบพาเรนต์

ตัวอย่าง (Example)

<!DOCTYPE html> <html> <head> <style> 
  div { 
    width: 70px; 
    height: 30px; 
    border: 3px solid brown; 
    box-shadow: 0 20px 0 -3px orchid; 
    z-index:-1; 
    position: relative; 
    animation: move 5s infinite; 
    animation-play-state: play; 
  } 
  @keyframes move { 
    from {top: 0px; } 
    to {top: 400px;} 
  } 
</style> 
<script> 
  function stateToggle(){ 
    document.getElementById("DIV1").style.animationPlayState="paused"; 
    document.getElementById("Sample").innerHTML="The animation is now paused"; 
  } 
</script> </head> 
<body> 
<div id="DIV1"></div> 
<p>Click the below button to toggle the above animation state</p> 
<button onclick="stateToggle()">CHANGE STATE</button> 
<p id="Sample"></p> 
</body> </html>

ผลลัพธ์ (Output)

ผลลัพธ์ที่ได้ กล่องเคลื่อนที่จากบนลงล่าง:

คุณสมบัติ HTML DOM Style animationPlayState

เมื่อคลิก CHANGE STATE:

คุณสมบัติ HTML DOM Style animationPlayState