简体   繁体   English

在 Ionic5 Angular 中从暗模式切换到亮模式时更改图像

[英]changing image when switch from dark mode to light in Ionic5 Angular

Hi I'm trying to switch the image when going from dark to light mode or vs versa.嗨,我正在尝试从暗模式切换到亮模式时切换图像,反之亦然。 I've tried the following with no success;我尝试了以下但没有成功;

HTML HTML

<picture>
  <source 
    srcset="dark.png" 
    media="(prefers-color-scheme: dark)">
  <img src="light.png">
</picture>

CSS CSS

#screenshot {
        background-image: url(settings-light.png);
      }

      @media (prefers-color-scheme: dark) {
        #screenshot {
          background-image: url(settings-dark.png);
        }
      }

I have a toggle button to switch from dark to light which is out of the box with Ionic 5 side menu.我有一个切换按钮,可以从黑暗切换到明亮,这是 Ionic 5 侧面菜单开箱即用的。

Any help is greatly appreciated.任何帮助是极大的赞赏。

I actually was totally overcomplicating this.实际上,我完全把这个复杂化了。

Ionic provides a media query we can tap into. Ionic 提供了一个我们可以利用的媒体查询。

Did you try this out?你试过了吗?

https://dev.to/nodefiend/changing-dark-light-image-on-ionic-5-react-ios-app-57m5 https://dev.to/nodefiend/changeing-dark-light-image-on-ionic-5-react-ios-app-57m5

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

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