PerformanceElementTiming: element property
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Thuộc tính chỉ đọc element của giao diện PerformanceElementTiming trả về một Element là con trỏ tới phần tử được quan sát.
Giá trị
Một Element, hoặc null nếu phần tử là một phần tử shadow DOM.
Ví dụ
>Ghi lại phần tử được quan sát
Trong ví dụ này, một phần tử <img> đang được quan sát bằng cách thêm thuộc tính elementtiming. Một PerformanceObserver được đăng ký để lấy tất cả các mục hiệu suất loại "element" và cờ buffered được dùng để truy cập dữ liệu từ trước khi trình quan sát được tạo. Phần tử DOM được quan sát được ghi ra console.
html
<img src="image.jpg" alt="a nice image" elementtiming="big-image" />
js
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (entry.identifier === "big-image") {
console.log(entry.element);
}
});
});
observer.observe({ type: "element", buffered: true });
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Element Timing API> # dom-performanceelementtiming-element> |