html - 如何在 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 操场上尝试了这段代码,我可以看到选定的幻灯片文本在渲染时变化良好 - 选定的幻灯片:第一张幻灯片上的 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>
推荐阅读
- html - HTML、CSS 随机大小自对齐对齐的图片库
- javascript - 如何使用 nextjs、node 和solid library 安装一个solid server?
- python - 使用 XBee Python 库的 dest_addr 的正确格式是什么?
- go - 将文件系统添加到现有 http api Web 服务器的最佳方法
- reactjs - 无法设置多个复选框的状态?
- php - 从数据中保存文件
- dart - void Function(int) 不是 void Function(dynamic) 的有效覆盖
- javascript - React Native Firebase auth().signInWithPhoneNumber() 在发布 APK 中返回意外错误
- sql - 创建变量 myhospitalstaff
- javascript - 正则表达式和函数语法