动态高度的放大器清单 [英] amp-list with dynamic height

查看:88
本文介绍了动态高度的放大器清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是放大器清单,我希望根据得到的结果得出一个动态的高度.有办法吗?我做不完.

I'm using amp-list and I would like to have a dynamic height based on the results that I got. There is a way to do it? I couldn't get it done.

<amp-list src="request-url">
    <template type="amp-mustache" id="amp-template-id">
    ...
    </template>
</amp-list>

所有可用的布局都需要在放大器清单级别或父级别的尺寸.但是我不想指定高度.我的结果可以包含1或12个项目.

All the available layouts requires dimensions at the amp-list level or parent level. However I don't want to specify an height. My results can either have 1 or 12 items.

推荐答案

AMP中没有动态布局(这是为了避免页面加载时的重排,这是AMP的一大优势).但是,如果需要(并且可用),则放大器清单将自动占用更多空间.

There is no dynamic layout in AMP (this is to avoid reflow while the page is loading, which is one of the big advantages of AMP). However, the amp-list will automatically take more space if required (and available).

您可以做以下三件事来支持这一点:

You can do the following three things to support this:

  1. 使用高度固定的高度布局以包括第一个元素.这样可以确保在只有一个元素的情况下,列表不会占用太多空间.
  2. 指定一个溢出按钮,以防列表折叠.
  3. 启用amp运行时,方法是将列表放置在初始视口以下或尽可能远地放置在底部,以使该列表具有更多空间.

这是官方文档对此所说的话:

Here is what the official docs say about this:

如果amp-list加载后需要更多空间,它将请求AMP运行时使用正常AMP流更新其高度.如果AMP Runtime无法满足对新高度的要求,它将在可用时显示溢出元素.但是请注意,典型的amp-list元素在文档底部的放置几乎总是保证AMP Runtime可以调整其大小.

If amp-list needs more space after loading it requests the AMP runtime to update its height using the normal AMP flow. If AMP Runtime cannot satisfy the request for new height, it will display overflow element when available. Notice however, the typical placement of amp-list elements at the bottom of the document almost always guarantees that AMP Runtime can resize it.

来源: https://www.ampproject.org/docs/reference/组件/放大器清单

这篇关于动态高度的放大器清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆