CaptureController: phương thức resetZoomLevel()

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Phương thức resetZoomLevel() của giao diện CaptureController đặt lại mức thu phóng của bề mặt hiển thị đang được chụp về mức ban đầu là 100.

Phương thức resetZoomLevel() phải được gọi thông qua kích hoạt tạm thời. Ngoài ra, người dùng sẽ được hỏi quyền chia sẻ tab khi lần đầu cố gắng chụp màn hình; nếu người dùng từ chối cấp quyền thì mức thu phóng sẽ không thể thay đổi ngay cả khi có kích hoạt tạm thời.

Syntax

js
resetZoomLevel()

Parameters

Không có.

Return value

Một Promise hoàn tất với undefined.

Exceptions

InvalidStateError DOMException

Có một nỗ lực gọi resetZoomLevel() mà không có kích hoạt tạm thời.

NotAllowedError DOMException

Được ném ra khi:

Examples

Cách dùng resetZoomLevel() cơ bản

Đoạn mã sau thêm một trình lắng nghe sự kiện vào một nút để khi nút được nhấn, hàm resetZoom() được gọi. Hàm này sẽ gọi phương thức resetZoomLevel(), đặt lại mức thu phóng của bề mặt đang được chụp về 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();
}

Xem Using the Captured Surface Control API để có ví dụ đầy đủ đang hoạt động.

Specifications

Thông số kỹ thuật
Captured Surface Control
# dom-capturecontroller-resetzoomlevel

Browser compatibility

See also