如何在 amp-carousel 中放大绑定字幕?
how to amp bind caption in amp-carousel?
我需要轮播标题新闻。(滑块中的一些图片带有文字)。
这是一个官方示例:
<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
?
我在 AMP playground 中尝试了这段代码,我可以看到选定的幻灯片文本变化良好,如下所示 -
渲染 - 所选幻灯片: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>
我需要轮播标题新闻。(滑块中的一些图片带有文字)。
这是一个官方示例:
<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
?
我在 AMP playground 中尝试了这段代码,我可以看到选定的幻灯片文本变化良好,如下所示 - 渲染 - 所选幻灯片: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>