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

แอนิเมชั่นสไตล์ HTML DOM คุณสมบัติ PlayState


คุณสมบัติ animationPlayState ใช้สำหรับการตั้งค่าหรือรับสถานะแอนิเมชันไม่ว่าจะทำงานหรือหยุดชั่วคราว ซึ่งมีประโยชน์ในการสลับภาพเคลื่อนไหว

ไวยากรณ์

ต่อไปนี้เป็นไวยากรณ์สำหรับ

การตั้งค่าคุณสมบัติ animationPlayState -

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

คุณค่า

ต่อไปนี้เป็นค่า -

Sr.No ค่า &คำอธิบาย
1 กำลังทำงาน
ระบุว่าแอนิเมชั่นกำลังทำงานและเป็นค่าเริ่มต้น
2 หยุดชั่วคราว
สำหรับการระบุภาพเคลื่อนไหวจะหยุดชั่วคราว
3 เริ่มต้น
สำหรับการตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น
4 สืบทอด
เพื่อสืบทอดค่าคุณสมบัติหลัก

ตัวอย่าง

ให้เราดูตัวอย่างคุณสมบัติ animationPlayState -

<!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>

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้เมื่อกล่องเคลื่อนที่จากบนลงล่าง -

แอนิเมชั่นสไตล์ HTML DOM คุณสมบัติ PlayState

เมื่อคลิกเปลี่ยนสถานะ -

แอนิเมชั่นสไตล์ HTML DOM คุณสมบัติ PlayState