MediaTrackSupportedConstraints: aspectRatio 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

MediaTrackSupportedConstraints 字典的 aspectRatio 屬性是一個只讀的布林值。當 MediaDevices.getSupportedConstraints() 返回的物件中包含此屬性(並且其值為 true)時,表示 使用者代理 支援 aspectRatio 約束。如果不支援該約束,它將不會包含在列表中,因此此值永遠不會是 false

您可以透過呼叫 navigator.mediaDevices.getSupportedConstraints() 來訪問支援的約束字典。

如果使用者代理支援 aspectRatio 約束,則該屬性會存在於字典中(並且其值始終為 true)。如果該屬性不存在,則表示它缺少於支援的約束字典中,如果您嘗試檢視其值,將得到 undefined

示例

js
const result = document.getElementById("result");
const supported = navigator.mediaDevices.getSupportedConstraints().aspectRatio;
result.textContent = supported ? "Supported!" : "Not supported!";

結果

規範

規範
媒體捕獲和流
# dom-mediatrackconstraintset-aspectratio

瀏覽器相容性

另見