Skip to content
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

wxss 不能引用本地图片 #4

Open
longyiyiyu opened this issue Feb 2, 2019 · 2 comments
Open

wxss 不能引用本地图片 #4

longyiyiyu opened this issue Feb 2, 2019 · 2 comments
Labels
css about css experience learn from this

Comments

@longyiyiyu
Copy link
Contributor

只能引用线上图片或者 base64

@longyiyiyu longyiyiyu added experience learn from this css about css labels Feb 2, 2019
@longyiyiyu
Copy link
Contributor Author

实际上是不需要在 wxss 里面使用本地图片的。

一般使用到图片的地方是 background,除了利用雪碧图技术之外,单独图片都可以使用 <image> 代替。

雪碧图技术是为了减少图片请求,但是小程序会把所有本地图片打包到程序包里,跟着代码一起下载下来,不存在请求的问题

有人会说图片太大?需要减小小程序包大小?但是问题是你见过有对大图片进行合并雪碧图的吗?

雪碧图本来就是给小图标用的

因此,在微信小程序不需要用雪碧图!

有一种场景可能感觉很需要雪碧图,那就是点击态图片,但实际上也可以通过 <image> 实现的,下面提供一个开发模式:

<button class="btn" open-type="share" hover-class="z-active">
  <image class="btn-icon" src="./images/[email protected]"></image>
  <image class="btn-icon f-active" src="./images/[email protected]"></image>
</button>
.btn {
  // ...

  &.z-active {
    .btn-icon {
      display: none;

      &.f-active {
        display: block;
      }
    }
  }
}
.btn-icon {
  // ...

  &.f-active {
    display: none;
  }
}

实际上就是使用两个 <image>,使用同一个样式,因为只是图片不一样
默认 active 的图片隐藏,点击的时候在替换一下就好了

@longyiyiyu
Copy link
Contributor Author

另外要用到 background 的地方就是背景图了,那就让 <images> 绝对定位就可以了

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

No branches or pull requests

1 participant