简体   繁体   English

AMP Carousel 不适用于多个项目

[英]AMP Carousel not working for more than one item

I trying to use carousel.我尝试使用轮播。

在此处输入图片说明

as per above image i try to set up a carousel but it is not changing automatically.根据上图,我尝试设置轮播,但它不会自动更改。 if i use responsive layout that it is changing automatically but it showing only one item at time.如果我使用响应式布局,它会自动更改但它一次只显示一项。


<amp-list id="list_id" width="350" height="150" layout="flex-item"
                    src="somesrc">
<template type="amp-mustache">
                        <amp-carousel width="350" height="150" layout="fixed" type="carousel" autoplay delay="2000"
                            loop>
                            {{#values}}
                            <div role="text">
                                <amp-img src="{{image_link}}" layout="fixed" width="100" height="100" alt="{{title}}"
                                    role="button" tabindex="0"
                                    on="tap:AMP.setState({ mytext: 'somedata' })">
                                </amp-img>
                                <p class="category_label">{{category}}</p>
                            </div>
                            {{/values}}
                        </amp-carousel>
                    </template>
                </amp-list>

is there any way for auto change of carousel if more than one item display at same time.如果同时显示多个项目,是否有任何方法可以自动更改轮播。

Scripts:脚本:

<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
    <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
    <script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.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-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>

Thanks Vishal谢谢维沙尔

I got solution of this problem.我得到了这个问题的解决方案。 for more than one item and auto change feature we can not use amp-carousel we have to use amp-base-carousel.对于多个项目和自动更改功能,我们不能使用 amp-carousel,我们必须使用 amp-base-carousel。

Require Script:需要脚本:

<script async custom-element="amp-base-carousel" src="https://cdn.ampproject.org/v0/amp-base-carousel-0.1.js"></script>

Code:代码:

<amp-list id="list_id" width="350" height="150" layout="flex-item"
                    src="your url">
                    <template type="amp-mustache">
                        <amp-base-carousel width="350" height="150" layout="fixed" snap="true" auto-advance="true" visible-count="3"
                            loop="true">
                            {{#values}}
                            <div role="text">
                                <amp-img src="{{image_link}}" layout="fixed" width="100" height="100" alt="{{title}}"
                                    role="button" tabindex="0">
                                </amp-img>
                                <p class="category_label">{{category}}</p>
                            </div>
                            {{/values}}
                        </amp-base-carousel>
                    </template>
                </amp-list>

check this links github issue and amp-base-carousel .检查此链接github issueamp-base-carousel

Thanks谢谢

Vishal维沙尔

"autoplay" attribute works with "type=slides" and slides will have only single slide at a time. “自动播放”属性与“type=slides”配合使用,幻灯片一次只能有一张幻灯片。 You are mixing up two thing, "autoplay" with "type=carousel" which is not possible as per current rules of amp-carousel.您正在混淆两件事,“自动播放”和“类型=轮播”,根据当前的 amp-carousel 规则,这是不可能的。 You can read about this here on AMP play ground's carousel page(3rd section) : AMP playground您可以在 AMP 游乐场的轮播页面(第 3 部分)上阅读有关此内容的信息: AMP 游乐场

As per my limited knowledge this restriction is there because autoplay advances to next slide, now if in carousel type, that pointer from where to scroll will not be there, because it depends upon the screen size how many images will be there in one slide, it also might possible that half of the image comes in 1st slide and another half of that image comes in next slide so that might be the reason.根据我有限的知识,存在此限制是因为自动播放前进到下一张幻灯片,现在如果在轮播类型中,滚动位置的指针将不存在,因为这取决于屏幕大小,一张幻灯片中将有多少图像,也有可能图像的一半出现在第一张幻灯片中,而该图像的另一半出现在下一张幻灯片中,这可能是原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM