CaptureController: resetZoomLevel() 方法
CaptureController 介面的 resetZoomLevel() 方法會將捕獲的顯示錶面縮放重置到初始級別 100。
resetZoomLevel() 方法必須透過 瞬時啟用 呼叫。此外,當首次嘗試螢幕捕獲時,使用者會被請求分享標籤頁的許可權;如果使用者拒絕許可權,則即使有瞬時啟用,縮放級別也無法更改。
語法
js
resetZoomLevel()
引數
無。
返回值
異常
InvalidStateErrorDOMException-
嘗試在沒有瞬時啟用的情況下呼叫
resetZoomLevel()。 NotAllowedErrorDOMException-
丟擲時
- 頁面的
captured-surface-control許可權策略不允許頁面使用 Captured Surface Control API。 - 使用者明確拒絕了捕獲顯示圖面的許可權。
- 頁面的
示例
resetZoomLevel() 基本用法
以下程式碼段為按鈕添加了事件監聽器,以便在點選按鈕時呼叫 resetZoom() 函式。該函式又呼叫 resetZoomLevel() 方法,將捕獲的表面的縮放級別重置為 100。
js
// Create controller and start capture
const controller = new CaptureController();
videoElem.srcObject = await navigator.mediaDevices.getDisplayMedia({
controller,
});
// ...
resetBtn.addEventListener("click", resetZoom);
async function resetZoom() {
await controller.resetZoomLevel();
}
有關完整的可執行示例,請參閱 使用 Captured Surface Control API。
規範
| 規範 |
|---|
| Captured Surface Control # dom-capturecontroller-resetzoomlevel |
瀏覽器相容性
載入中…