[英]Zoom Function in a Webview with Electron
I'm trying to create a zoom in and a zoom out button for my webview in my Electron app. 我正在尝试在Electron应用程序中为Web视图创建一个放大和一个缩小按钮。
Currently, I did it like this but getZoomFactor
always returns undefined
. 目前,我是这样做的,但是getZoomFactor
总是返回undefined
。 Is there another way of creating these two zoom buttons? 还有另一种创建这两个缩放按钮的方法吗?
function zoomIn() {
const webview = document.querySelector('webview');
let actualZoom = webview.getZoomFactor();
if (actualZoom == null) {
actualZoom = 1;
}
webview.setZoomFactor(actualZoom + 1);
}
function zoomOut() {
const webview = document.querySelector('webview');
let actualZoom = webview.getZoomFactor();
if (actualZoom == null) {
actualZoom = 1;
}
webview.setZoomFactor(actualZoom - 1);
}
The WebView's getZoomLevel takes a callback instead of returning a value. WebView的getZoomLevel接受回调,而不返回值。
.getZoomLevel(callback) callback Function .getZoomLevel(callback)回调函数
zoomLevel Number Sends a request to get current zoom level, the callback will be called with callback(zoomLevel). zoomLevel Number发送请求以获取当前缩放级别,该回调将通过callback(zoomLevel)进行调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.