Skip to content

一个有趣的暗黑模式实现 #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jsonz1993 opened this issue Aug 31, 2021 · 1 comment
Open

一个有趣的暗黑模式实现 #33

jsonz1993 opened this issue Aug 31, 2021 · 1 comment
Labels

Comments

@jsonz1993
Copy link
Owner

jsonz1993 commented Aug 31, 2021

今天在群里看到有人分享一个暗黑模式下很有意思的主题。

大概的效果是这样的,点了暗黑模式之后,整个屏幕都黑了,只开了一盏小灯。

Kapture 2021-08-31 at 18 52 02

一开始很好奇这是怎么实现的,第一反应想到的是用svg去处理。毕竟我不熟悉svg,所以我觉得svg无所不能....

最后看了源码,发现只是加了一个背景图....大致思路是这样:

点击后整个body的背景色设置为#000,然后加一个背景图,因为背景图是在背景色的上层,所以当你的背景图在某些文字下面的话,一对比就看得到文字,很巧妙的实现。

拉出来实现的一个小demo

源代码传送门

原博客传送门: https://tonsky.me/blog/swiftui
ps: 可以拉到最下面鼠标移动到作者的自拍上,有个小彩蛋,太有意思了 😆

@jsonz1993 jsonz1993 added the Css label Sep 5, 2021
@hhking
Copy link

hhking commented Oct 26, 2021

jsonz 太强了

毕竟我不熟悉svg,所以我觉得svg无所不能....

我也觉得

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants