幻灯片广告
摘要
使用 amp-carousel 创建交互式广告的 AMPHTML 广告示例。
样式
这是一个高级示例,需要一些样式才能使其外观和功能正常。
<style amp-custom>
/* Main element that contains the creative. */
.root-container {
font-family: 'Roboto', sans-serif;
font-size: 12px;
background: #151717 url(/static/samples/img/car-mesh.jpg) center center;
background-size: cover;
color: #fff;
width: 100%;
height: 100vh;
position: relative;
display: flex;
flex-direction: column;
overflow: hidden;
}
.root-container h1 {
font-weight: normal;
margin: 10px 0 0;
text-align: center;
text-transform: uppercase;
font-size: 12px;
}
.carousel-container {
position: relative;
flex: 1;
display: flex;
justify-content: center;
flex-direction: column;
}
.carousel-img {
display: block;
}
/*
* Dimensions of the carousel item are the same as the size of each image
* plus the border width. Using `calc()` for the sake of the example.
*/
.carousel-item {
width: calc(216px + 2 * 4px);
height: calc(117px + 2 * 4px);
box-sizing: border-box;
background: #000;
float: left;
}
.carousel-item .carousel-img {
border: 4px solid #c9cccc;
}
/* Styling for footer */
.footer {
background: #000;
box-sizing: border-box;
padding: 8px;
display: flex;
}
.stretch {
flex: 1;
}
.logo-img {
display: block;
}
.button {
text-transform: uppercase;
padding: 8px;
color: #fff;
display: inline-block;
background-color: #2979ff;
}
.button-secondary {
background: transparent;
border-right: 1px solid white;
margin-right: 8px;
}
</style>
轮播图
我们使用 amp-carousel
组件来显示多个幻灯片。
所有具有 carousel-item
类名的元素本质上具有相同的标记。
AMP 有一个用于 事件和操作 的系统。 它使用一种领域特定语言来描述如何触发操作。 在此示例中,我们将操作系统与 amp-bind
结合使用,以保持当前选定幻灯片的状态变量。
这仅用于当选定项目滑动到视图中时激活的过渡效果。 如果不需要过渡效果,则此示例不再需要 amp-bind
。
<amp-carousel
height="132"
layout="fixed-height"
type="slides"
class="carousel"
controls>
<div class="carousel-item">
<amp-img src="/static/samples/img/car-sideview2.jpg"
width="216"
height="117"
layout="fixed"
class="carousel-img"></amp-img>
</div>
<div class="carousel-item">
<amp-img src="/static/samples/img/car-gauges.jpg"
width="216"
height="117"
layout="fixed"
class="carousel-img"></amp-img>
</div>
<div class="carousel-item">
<amp-img src="/static/samples/img/car-sideview1.jpg"
width="216"
height="117"
layout="fixed"
class="carousel-img"></amp-img>
</div>
</amp-carousel>
</div>
广告页脚
通过使用操作系统,我们可以在点击“查找商店”按钮时激活灯箱。
<div class="footer">
<div class="stretch">
<amp-img src="/static/samples/img/car-logo.png"
width="72"
height="32"
layout="fixed"
class="logo-img"></amp-img>
</div>
<a href="https://amp.org.cn/documentation/examples/" target="_blank" class="button button-secondary">
Locate Store
</a>
<a href="https://amp.org.cn/documentation/examples/" target="_blank" class="button">
Explore
</a>
</div>
需要进一步解释?
如果此页面上的解释没有涵盖您所有的问题,请随时联系其他 AMP 用户来讨论您的具体用例。
前往 Stack Overflow 一个未解释的功能?AMP 项目强烈鼓励您的参与和贡献! 我们希望您成为我们开源社区的持续参与者,但我们也欢迎您对您特别感兴趣的问题做出一次性贡献。
在 GitHub 上编辑示例-
由 @zhouyx 编写