ionic2 : content in slides not scrolling

2019-04-12 12:54发布

I have a couple of slides which have dynamic content that is added to them. The problem is the content inside of the slides doesn't scroll. So if I have a lot of items only some show and there is no ability to slide. How can I make it so the content in my lists slides inside of their slides?

<ion-content>
    <ion-slides (change)="onSlideChanged($event)">
        <ion-slide >
            <ion-list>
            <ion-item *ngFor="#item of items1; #i = index">
            <h2>{{item}</h2>
            </ion-item>
            </ion-list>
        </ion-slide>
         <ion-slide>
                 <ion-list>
            <ion-item *ngFor="#item of items2; #i = index">
            <h2>{{item}</h2>
            </ion-item>
            </ion-list>
        </ion-slide>
    </ion-slides>
</ion-content>

4条回答
贪生不怕死
2楼-- · 2019-04-12 13:24

Looks like you need to wrap your long content in a <scroll-content> inside of each <ion-slide>, for example:

<ion-slides>
    <ion-slide *ngFor="#item of items">
      <scroll-content>
        <h1>{{item.title}}</h1>
        <p>{{item.description}}</p>
      </scroll-content>
    </ion-slide>
</ion-slides>

Note, you may need to do a text-align:left if you want the text to not be centered, since thats the default for content in <ion-slide>.

查看更多
叼着烟拽天下
3楼-- · 2019-04-12 13:29

I have the same problem,and I solve it like this:

    <ion-slides style="height: auto">
       <ion-slide *ngFor="#item of items">
           <h1>{{item.title}}</h1>
           <p>{{item.description}}</p>
       </ion-slide>
    </ion-slides>
查看更多
老娘就宠你
4楼-- · 2019-04-12 13:31

In controller, put:

ngAfterViewInit() {
  this.slides.autoHeight = true;
}
查看更多
混吃等死
5楼-- · 2019-04-12 13:36

Setting style='height:auto' as stated in booyoungxu's answer disables sliding after you swipe on the first slide. style='overflow:scroll' works best.

<ion-slides style="height: auto">
...
</ion-slides>
查看更多
登录 后发表回答