amp-list with flexible height to a max

。_饼干妹妹 提交于 2019-12-13 04:07:29

问题


I want to provide a list which will vary with the input of a text box. This list will provide the results for that search query. I am using amp-list for this.

I want the list height to adjust to the number of results (flex-item should be fine here). But I want the list to have a max height of e.g. 500px and no more

Is this possible? Thank you very much


回答1:


Dynamic resizing is currently in the works: see this thread on GitHub - although not sure if this applies in your current situation. Are you able to provide the code or a link to what you're currently working on?

To accomplish the max-height with an overflow of scroll, put a container div around the amp-list. Something like below.

div#list-container {
  max-height: 500px;
  overflow: scroll;
}
<div id="list-container">
  <amp-list>
  </amp-list>
</div>



回答2:


You can use amp-bind to dynamically update the amp-list height based on the number of search results:

<amp-list layout="fixed-height"
  height="0"
  src="/results"
  [src]="searchResults"
  [height]="searchResults.length < 5 ? 100 * searchResults.length : 500">
  <template type="amp-mustache">
    // search results
  </template>
</amp-list>

I assumed that a single search result has a height of 100px and that the results are contained in an amp-state variable called searchResults.

Here is a working sample demonstrating how to dynamically resize an amp-list.



来源:https://stackoverflow.com/questions/51614270/amp-list-with-flexible-height-to-a-max

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!