amp-html - AMP 在 Show More 上显示加载指示器

标签 amp-html accelerated-mobile-page google-amp amp-list

我关注了this example在 AMP 上实现“显示更多”操作。它工作得很好,但是当我点击按钮时,它没有显示任何内容来让用户知道页面正在加载。

我的后端不是特别快,所以看起来它直到最终加载时才工作。

the demo它也没有任何东西,但速度非常快。

有什么办法吗?即使它只是禁用按钮。我没有在列表或表单上看到任何类更改以在 CSS 上使用它们。

这是我的代码:

amp-state id="#{section}State" src="#{path}"
amp-state id="#{section}"
  script type="application/json"
    | {
    | "page": 2,
    | "hasMorePages": true
    | }
|<amp-list src="#{path}" layout="responsive" height="600px" width="600px" [src]="#{section}State.items" [height]="(#{section}State.items.length / 3) * 400">
template[type="amp-mustache"]
  = render partial: item_template, locals: { image: image }
|</amp-list>
form method="GET" action="#{path}" action-xhr="#{path}" target="_top" on="submit-success: AMP.setState({ #{section}State: { items: #{section}State.items.concat(event.response.items) }, #{section}: { page: #{section}.page + 1, hasMorePages: event.response.hasMorePages } });" novalidate=""
  |<input type="hidden" name="page" value="2" [value]="#{section}.page">
  |<input type="submit"
         value="Show more"
         class="show-more"
         [class] = "(#{section}.hasMorePages == false ? 'hide' : 'ampstart-btn caps m1 mb3 show show-more')">

它只是示例中的那个,只是做了一些命名更改。

最佳答案

有两种方法可以在提交表单时显示加载指示器:

  1. 使用 amp-form 的内置 submitting 状态:

    <form ...>
      ...
      <button>Show more</button>
        ...
      <div submitting>
         Loading...
      </div>
    </form>
    
  2. 如果您需要更大的灵 active ,您可以在 amp-state 变量中跟踪表单状态,例如myFormState,然后根据不同的表单提交事件进行更新。根据变量,您可以在页面上隐藏和显示不同的元素:

    <form on="submit:         AMP.setState( { myFormState: 'submitting' } ),
              submit-success: AMP.setState( { myFormState: 'success' } ),
              submit-error:   AMP.setState( { myFormState: 'error' } )
             " ... >
    
    <amp-list [hidden]="myFormState != 'success'" ... > ... </amp-list>
    <div hidden [hidden]="myFormState != 'submitting'" ...>Loading</div>
    <div hidden [hidden]="myFormState != 'error'" ...>Something went wrong :-(</div>
    

关于amp-html - AMP 在 Show More 上显示加载指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52151979/

相关文章:

amp-html - AMP(加速移动页面)可以/应该用于整个商业网站吗?

google-analytics - 有没有办法阻止 AMP Analytics 将开发工作计为点击?

javascript - AMP 下拉错误 : 'onchange' may not appear in tag 'select'

google-analytics - AMP 页面添加了 Google Analytics Amp Analytics 错误

javascript - 如何从 firebase 在 Accelerated Mobile Pages(AMP) 中显示数据

amp-html - AMP 表单 - 在表单提交后显示相同的 html 并添加一些附加元素

asp.net-core-mvc - 在 ASP.NET MVC 中自动切换 AMP 的 View

html - 全屏汉堡覆盖菜单(不使用 JavaScript/Jquery)

amp-html - 如何在 AMP-html 中将数字格式化为货币?

google-analytics - 谷歌 AMP 和谷歌分析