简体   繁体   English

如何用电子制作半透明的app背景?

[英]How to make a semi-transparent app background with electron?

I'm quite new to Electron and am wondering how i can create the effect where parts of an application are partially transparent, and show a blurred image of the applications below them. 我对Electron很新,我想知道如何在应用程序的某些部分部分透明的情况下创建效果,并显示其下方应用程序的模糊图像。
This screenshot of Canary, an email app is a good example of what I mean. 这个电子邮件应用程序Canary的屏幕截图就是我的意思的一个很好的例子。 Canary的截图,一个邮件应用程序。注意侧边栏的半透明模糊背景

(I edited out my emails in preview) (我在预览中编辑了我的电子邮件)

How would I go about creating an effect similar to this in Electron? 我将如何在Electron中创建类似于此的效果? Specifically, how would I make a <div> element show a blurred version of the applications below it? 具体来说,我如何让<div>元素显示下面的应用程序的模糊版本? Is this even possible with Electron? Electron可以实现这一点吗?

Thank you for your help in advance. 提前谢谢你的帮助。

When setting up the browser window in your main.js file, set the vibrancy option to one of electrons options. 在main.js文件中设置浏览器窗口时,将vibrancy选项设置为电子选项之一。

A snippet from electrons documents below 下面是electrons documents的片段

"vibrancy String (optional) - Add a type of vibrancy effect to the window, only on macOS. 
Can be appearance-based, light, dark, titlebar, selection, menu, popover, sidebar, medium-light or ultra-dark."

https://github.com/arkenthera/electron-vibrancy/blob/master/README.md https://github.com/arkenthera/electron-vibrancy/blob/master/README.md

example js code if using the ultra-dark theme 示例js代码,如果使用超暗主题

let mainWindow; 让mainWindow;

const createWindow = () => {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    vibrancy: 'ultra-dark',
  });
};

After setting up the main window's background with the vibrancy set then simply split the window up with a sidebar and the main content. 在设置了主窗口的背景和振动设置后,只需用侧边栏和主要内容将窗口分开。 Setting the background color of main to any color you wish leaving the sidebar still with its OSX style transparency 将main的背景颜色设置为您希望离开侧边栏的任何颜色仍然具有OSX样式透明度

I hope this helps 我希望这有帮助

你可以在window setOpacity(number)上使用一个函数,其中number可以根据你的喜好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM