动画无效的电子setSize

时间:2017-10-19 15:57:55

标签: javascript electron

我正在使用此代码调整OSX上的电子窗口大小:

document.getElementById("resize-btn2").addEventListener("click", function(e) {
    var window = remote.getCurrentWindow();
    window.setSize(1024, 786, animate);
});

它工作正常(调整大小)但是如果我尝试使用“animate”参数,我在控制台中出错:

  

未定义动画

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

正如您在the documentation中所看到的,animate是一个可以是布尔值的参数:

  

win.setSize(width,height [,animate])

     
      
  • width Integer
  •   
  • height Integer
  •   
  • animate布尔值(可选)macOS
  •   
     

将窗口调整为宽度和高度。

您正在传递一个名为animate的变量作为参数,我猜您没有在任何地方定义它,因此错误。

同样的方式widthheight是整数,你传递整数,animate是一个布尔值,你必须通过truefalse

window.setSize(1024, 786, true);
// or
window.setSize(1024, 786, false);

取决于您是否想要动画,仅适用于macOS,如文档所述。

相关问题