关于html:小程序深色模式样式适配

0次阅读

共计 609 个字符,预计需要花费 2 分钟才能阅读完成。

  1. 开启 DarkMode
    app.json 中配置 darkmodetrue,示意开启深色模式
  2. 配置变量文件 theme.json, 并在 app.json 中配置门路引入
    “themeLocation”:”theme.json”
  3. theme.json 中定义相干变量

    {
        "light": {
            "navigationBarBackgroundColor": "#fff",
            "navigationBarTextStyle": "black"
        },
        "dark": {
            "navigationBarBackgroundColor": "#000",
            "navigationBarTextStyle": "white"
        }
    }
  4. app.json 中利用配置属性,以 @ 结尾援用变量

    "window": {
        "navigationBarBackgroundColor": "@navigationBarBackgroundColor",
        "navigationBarTitleText": "考研政治定制学",
        "navigationBarTextStyle": "@navigationBarTextStyle"
    },
  5. WXSS 适配,通过媒体查问 prefers-color-scheme 适配不同主题
page {background: #f2f2f2;}
@media (prefers-color-scheme: dark) {
    .page {background: #000;}
}

参考:小程序深色模式适配官网文档

正文完
 0