PerformanceElementTiming: identifier 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 identifier của giao diện PerformanceElementTiming trả về giá trị của thuộc tính elementtiming trên phần tử.

Giá trị

Một chuỗi.

Ví dụ

Sử dụng identifier

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. Giá trị của elementtimingbig-image. Do đó, việc gọi entry.identifier trả về chuỗi big-image.

html
<img
  src="image.jpg"
  alt="a nice image"
  elementtiming="big-image"
  id="myImage" />
js
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    if (entry.identifier === "big-image") {
      console.log(entry.naturalWidth);
    }
  });
});
observer.observe({ type: "element", buffered: true });

Thông số kỹ thuật

Thông số kỹ thuật
Element Timing API
# dom-performanceelementtiming-identifier

Tương thích trình duyệt