使用GSAP动画库并将ion-content绑定为滚动条,可使用以下代码示例:
HTML:
CSS: .inner-content { height: 100%; }
.card { margin-bottom: 20px; }
JS: import { Component } from '@angular/core'; import { GestureController, IonContent } from '@ionic/angular'; import { TimelineLite, Power2 } from "gsap";
@Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'] }) export class HomePage { items = [ { header: "Item 1", content: "This is content of item 1" }, { header: "Item 2", content: "This is content of item 2" }, { header: "Item 3", content: "This is content of item 3" } ];
private timeline: TimelineLite; private gesture: Gesture;
constructor(private gestureCtrl: GestureController) { }
ionViewDidEnter() { this.timeline = new TimelineLite({ paused: true });
let y = 0;
this.items.forEach((item, index) => {
let card = document.querySelectorAll('.card')[index] as HTMLElement;
let cardHeight = card.clientHeight;
this.timeline.to(card, { y: y, ease: Power2.easeOut });
y += cardHeight + 20;
});
this.gesture = this.gestureCtrl.create({
el: document.querySelector('.scroll-content'),
gesture