在Electron中,BrowserWindow的宽度和高度是通过像素值设置的,而不是百分比。但是,你可以通过计算屏幕的尺寸来达到宽度百分比的效果。
以下是一个示例,将BrowserWindow的宽度设置为屏幕宽度的80%:
const { app, BrowserWindow, screen } = require('electron')
app.whenReady().then(() => {
const { width, height } = screen.getPrimaryDisplay().workAreaSize
const win = new BrowserWindow({
width: Math.ceil(width*0.8), // 设置宽度为屏幕宽度的80%,向上取整,不支持小数
height:Math.ceil(height*0.8)
})
win.show()
})