简体   繁体   English

如何根据需要使Foundation Apps Interchange加载图像?

[英]How to make Foundation Apps Interchange load images as needed?

The documentation for the Foundation for Apps (and Angular Base Apps, which is the now-maintained fork of F4A) Interchange gives this example as a way to load only the small size of an image on mobile devices in order to save bandwidth: Foundation for Apps(和Angular Base Apps,这是现在维护的F4A分支)Interchange的文档提供此示例作为仅在移动设备上加载小尺寸图像以节省带宽的一种方法:

<ba-interchange>
    <img media="small" src="assets/img/small.jpg">
    <img media="medium" src="assets/img/medium.jpg">
    <img media="large" src="assets/img/large.jpg">
</ba-interchange>

However, while only the small image is displayed, the browser still sees three img tags and requests all three images, before angular is even loaded. 但是,虽然只显示小图像,但浏览器仍会看到三个img标签并请求所有三个图像,甚至还没有加载Angle。 This defeats the purpose of using the interchange at all, at least, if your purpose is to save bandwidth. 至少在您的目的是节省带宽的情况下,这完全违背了使用交换的目的。

The Foundation 6 for Sites Interchange avoids this by putting all of the images into a data-interchange attribute string on the element instead. 站点交换基础6通过将所有图像放到元素上的data-interchange属性字符串中来避免这种情况。 Does F4A have something similar that I'm missing? F4A是否有我所缺少的类似内容? Or is there something about the above example code that I'm missing? 还是我缺少上面的示例代码?

I would suggest using the ba-if directive provided by Angular Base Apps. 我建议使用Angular Base Apps提供的ba-if指令。 This directive internally uses the ng-if directive, causing the img element to not be added to the DOM except when the specified media query is matched. 该指令内部使用ng-if指令,导致img元素不添加到DOM中,除非匹配指定的媒体查询。

Your code can be re-written as follows using the ba-if directive: 您可以使用ba-if指令以如下方式重写您的代码:

<img ba-if="small only" src="assets/img/small.jpg">
<img ba-if="medium only" src="assets/img/medium.jpg">
<img ba-if="large only" src="assets/img/large.jpg">

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

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