FontData: family property
Limited availability
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 family của giao diện FontData trả về họ của mặt phông chữ.
Đây là tên được sử dụng khi tham chiếu đến họ phông chữ từ code, ví dụ, trong thuộc tính font-family hoặc trong các vị trí trong quy tắc at @font-face như hàm local().
Ví dụ bao gồm:
- Apple SD Gothic Neo
- Arial Black
- Avenir Next
- Katari
- YuMincho +36p Kana
Giá trị
Một chuỗi.
Ví dụ
Đoạn code sau sẽ truy vấn tất cả các phông chữ có sẵn và ghi siêu dữ liệu. Điều này có thể được sử dụng, ví dụ, để điền vào điều khiển chọn phông chữ.
js
async function logFontData() {
try {
const availableFonts = await window.queryLocalFonts();
for (const fontData of availableFonts) {
console.log(fontData.postscriptName);
console.log(fontData.fullName);
console.log(fontData.family);
console.log(fontData.style);
}
} catch (err) {
console.error(err.name, err.message);
}
}
Thông số kỹ thuật
| Specification |
|---|
| Local Font Access API> # ref-for-dom-fontdata-family> |