我正在使用此代码在 OSX 上调整 Electron 窗口的大小:
document.getElementById("resize-btn2").addEventListener("click", function(e) {
var window = remote.getCurrentWindow();
window.setSize(1024, 786, animate);
});
它工作正常(调整大小),但如果我尝试使用“animate”参数,我会在控制台中收到错误:
animate is not defined
我在这里做错了什么?
最佳答案
正如您在 the documentation 中看到的那样, animate 是一个可选参数,需要是 bool 值:
win.setSize(width, height[, animate])
- width Integer
- height Integer
- animate Boolean (optional) macOS
Resizes the window to width and height.
您正在传递一个名为 animate
的变量作为参数,我猜您没有在任何地方定义它,因此会出现错误。
同样的方式,宽度
和高度
是整数,你传递整数,animate
是一个 bool 值,你必须传递true
或 false
:
window.setSize(1024, 786, true);
// or
window.setSize(1024, 786, false);
取决于您是否需要动画,仅适用于 macOS
,如文档所述。
关于javascript - Electron setSize 动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46834087/