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

  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;
    }
}

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

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理