【问题标题】:sass: how to render different images for mobile onlysass:如何仅为移动设备渲染不同的图像
【发布时间】:2018-08-01 19:36:48
【问题描述】:

我不是 100% 清楚如何为仅移动视图实现与桌面视图不同的图像

例如,如果我有这个桌面图像:

&.card {
        .card-image {
          @include background-helper('gallery/old-pic.jpg', center, contain, no-repeat);
        }
      }

来自我有这段代码的 mixin 文件:

@mixin background-helper($image: false, $position: center, $size: contain, $repeat: no-repeat){
  @if $image {
    background-image: asset-url($image);
    background-repeat: $repeat;
    background-size: $size;
    background-position: $position;
  }
}

如果用户在手机上查看它,我不确定添加什么逻辑会告诉我的应用程序呈现 old-pic.jpg 以外的内容。

【问题讨论】:

    标签: sass breakpoint-sass


    【解决方案1】:

    看来您必须使用媒体查询。 例如:

    $break-small: 320px;
    $break-large: 1200px;
    
    .card-image {
      @media screen and (max-width: $break-small) {
        @include background-helper('gallery/mobile-pic.jpg', center, contain, no-repeat);
      }
      @media screen and (min-width: $break-large) {
        @include background-helper('gallery/old-pic.jpg', center, contain, no-repeat);
      }
    }
    

    【讨论】:

    • 不确定您的修复是否有效。我尝试为不同的卡片选择器制作所有相同的移动图像,但这没有渲染。但是,当我给它错误的移动资产路径时,它确实会中断。我在 Chrome devtools 控制台中没有看到不同的尺寸。
    猜你喜欢
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多