admin管理员组文章数量:1394079
So I'm experiencing issue when I'm trying to make a window transparent. I made tranparent: true, frame: false
but it doesn't really work. It removes the frame and stuff but doesn't do what I want till the end. I want it to be like really transparent. What I get is a: frameless window which is not transparent.
Help would be appreciated. Some code:
main.js
// main.js
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron')
const { maxHeaderSize } = require('http')
const path = require('path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: maxHeaderSize,
height: maxHeaderSize,
transparent:true,
frame: false
})
// and load the index.html of the app.
mainWindow.loadFile('bodycam.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.whenReady().then(() => {
function onAppReady() {
createWindow()
app.on('activate', function () {
// On macOS it's mon to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
}
setTimeout(onAppReady, 300)
})
// Quit when all windows are closed, except on macOS. There, it's mon
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
// In this file you can include the rest of your app's specific main process
some part of the code (that affects html body) from style.css (that's being linked with bodycam.html)
body {
margin: 0px auto;
overflow: hidden;
font-family: 'Share Tech Mono', monospace;
font-size: 13px;
}
So I'm experiencing issue when I'm trying to make a window transparent. I made tranparent: true, frame: false
but it doesn't really work. It removes the frame and stuff but doesn't do what I want till the end. I want it to be like really transparent. What I get is a: frameless window which is not transparent.
Help would be appreciated. Some code:
main.js
// main.js
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron')
const { maxHeaderSize } = require('http')
const path = require('path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: maxHeaderSize,
height: maxHeaderSize,
transparent:true,
frame: false
})
// and load the index.html of the app.
mainWindow.loadFile('bodycam.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.whenReady().then(() => {
function onAppReady() {
createWindow()
app.on('activate', function () {
// On macOS it's mon to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
}
setTimeout(onAppReady, 300)
})
// Quit when all windows are closed, except on macOS. There, it's mon
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
// In this file you can include the rest of your app's specific main process
some part of the code (that affects html body) from style.css (that's being linked with bodycam.html)
body {
margin: 0px auto;
overflow: hidden;
font-family: 'Share Tech Mono', monospace;
font-size: 13px;
}
Share
Improve this question
asked Jul 4, 2021 at 9:53
Nihad BadalovNihad Badalov
971 gold badge2 silver badges11 bronze badges
3
- Please visit help center, take tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a minimal reproducible example of your attempt, noting input and expected output, preferably in a Stacksnippet – mplungjan Commented Jul 4, 2021 at 9:55
- @mplungjan hi. Um I'd like to know if my question is clear enough. If it is not, I could explain more what I would like to get as a result of the code. – Nihad Badalov Commented Jul 4, 2021 at 10:05
- Did you check other questions, like stackoverflow./questions/53538215/… ? – Daantje Commented Jul 4, 2021 at 10:27
1 Answer
Reset to default 4Why you are facing this issue
In your case, you are facing this issue because you are trying to define the size of the window from the maxHeaderSize
value, wich es from the http Node API. And this... Actually makes no sense. The value of maxHEaderSize
is probably way bigger than the size of your screen. Electron seems to be suffering when creating a transparent window that big.
How to fix
You just need to remove that crazy value when creating your BrowserWindow. For example :
const mainWindow = new BrowserWindow({
transparent: true,
frame: false,
})
If you want to set your window at the same size of your screen, you can use the fullscreen
option :
const mainWindow = new BrowserWindow({
transparent: true,
frame: false,
fullscreen: true,
})
Finally, if you want your user to be able to "click throught the window", you probably will be interested in the setIgnoreMouseEvents method :
const mainWindow = new BrowserWindow({
transparent: true,
frame: false,
fullscreen: true,
})
mainWindow.setIgnoreMouseEvents(true)
本文标签: javascriptElectronMake transparent window with no backgroundStack Overflow
版权声明:本文标题:javascript - Electron - Make transparent window with no background - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744592965a2614605.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论