如何在安培转盘中安培字幕?

问题描述 投票:1回答:1

我需要一个轮播新闻标题。(滑块中的一些图片带有文字)。

这是一个官方示例:

<amp-carousel controls
  type="slides"
  width="400"
  height="300"
  [slide]="selectedSlide"
  on="slideChange:AMP.setState({ selectedSlide: event.index })">
  <amp-img src="/static/samples/img/image1.jpg"
    layout="fill"></amp-img>
  <amp-img src="/static/samples/img/image2.jpg"
    layout="fill"></amp-img>
  <amp-img src="/static/samples/img/image3.jpg"
    layout="fill"></amp-img>
</amp-carousel>

<h1>Selected slide: <span [text]="+selectedSlide + 1">1</span>/3</h1>

如何在[text]中代替selectedSlide设置每个图像的标题?

html css amp-html
1个回答
0
投票

我在AMP游乐场中尝试了此代码,我可以看到所选幻灯片文本的变化很好-渲染时-选定的幻灯片:1/3在第一张幻灯片上-所选幻灯片:2/3在第二张幻灯片上-选定的幻灯片:3/3

我不确定,但是我测试过这里的代码,检查您是否错过了amp-bind脚本?

<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
  <title>amp-carousel</title>
  <script async src="https://cdn.ampproject.org/v0.js"></script>

  <script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
  <script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
  <link rel="canonical" href="https://amp.dev/documentation/examples/components/amp-carousel/index.html">
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>

</head>
<body>


 <amp-carousel controls
  type="slides"
  width="400"
  height="300"
  [slide]="selectedSlide"
  on="slideChange:AMP.setState({ selectedSlide: event.index })">
  <amp-img src="/static/samples/img/image1.jpg"
    layout="fill"></amp-img>
  <amp-img src="/static/samples/img/image2.jpg"
    layout="fill"></amp-img>
  <amp-img src="/static/samples/img/image3.jpg"
    layout="fill"></amp-img>
</amp-carousel>

<h1>Selected slide: <span [text]="+selectedSlide + 1">1</span>/3</h1>


</body></html>
© www.soinside.com 2019 - 2024. All rights reserved.