Thuộc tính AnimationEvent trôi quaThời gian
Ví dụ
Hoạt ảnh đã chạy được bao nhiêu giây:
const div = document.getElementById("myDIV");
div.addEventListener("animationiteration", myRepeatFunction);
function myRepeatFunction(event) {
this.innerHTML = "Elapsed time: " + event.elapsedTime;
}
Hãy tự mình thử »Sự miêu tả
Thuộc tính elapsedTime
trả về số giây hoạt ảnh đã chạy khi xảy ra sự kiện hoạt ảnh.
Thuộc tính elapsedTime
luôn trả về "0" cho sự kiện animationstart .
Giá trị elapsedTime
không bị ảnh hưởng nếu hoạt ảnh bị tạm dừng.
Thuộc tính elapsedTime
ở chế độ chỉ đọc.
Sự kiện hoạt hình
Event | Occurs When |
---|---|
animationstart | A CSS animation has started |
animationend | A CSS animation has completed |
animationiteration | A CSS animation is repeated |
Thuộc tính hoạt hình
Property | Description |
---|---|
animationName | The name of the animation |
elapsedTime | The number of seconds an animation has been running |
pseudoElement | The name of the pseudo-element of the animation |
Xem thêm:
Đối tượng sự kiện hoạt hình
Thuộc tính hoạt hình Phong cách
Hướng dẫn:
Cú pháp
event .elapsedTime
Chi tiết kỹ thuật
Giá trị trả về: | Một số. Số giây mà hoạt ảnh đã chạy. |
---|---|
Phiên bản DOM: | Sự kiện hoạt ảnh DOM cấp 3 |
Hỗ trợ trình duyệt
event.elapsedTime
là tính năng DOM Cấp 3 (2004).
Nó được hỗ trợ đầy đủ trong tất cả các trình duyệt hiện đại:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |