首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有Hammer滑动函数的ngFor在角7中分割索引

带有Hammer滑动函数的ngFor在角7中分割索引
EN

Stack Overflow用户
提问于 2020-08-18 06:29:33
回答 1查看 410关注 0票数 0

当使用锤子js滑动功能与*ngFor的角度。预期的结果是对特定的瓷砖指数进行滑动,而该瓷砖将被移除。但通过这样做,动画现在已经不起作用了。我所写的代码是:

https://stackblitz.com/edit/angular-animations-lib-demo-ahykzr?file=src%2Fapp%2Fapp.component.html

.html:

代码语言:javascript
复制
<div style="margin: 10px">
    
    <div class="container" *ngFor="let data of datas; let i = index">
      
        <mat-card class="example-card animated flip infinite" [@enter1] style="margin: 20px 0px;" 

        [@cardAnimator]="animationState" 
        (@cardAnimator.done)="resetAnimationState()"
        (swipeleft)="startAnimation('slideOutLeft',i)"
        (swiperight)="startAnimation('slideOutRight',i)">
          
        <div>
            <h4>{{data}}</h4>
        </div>
        </mat-card>
        
    </div>
    
</div>

.scss:

代码语言:javascript
复制
.e-header {
    padding-bottom: 20px;
}

.pt-3, .py-3 {
    padding-top: 1rem!important;
}
.container {
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}
.text-right {
    text-align: right!important;
}

.justify-content-end {
    -ms-flex-pack: end!important;
    justify-content: flex-end!important;
}
.h3, h3 {
    font-size: 27px;
    letter-spacing: 0px;
    line-height: 28px;
    font-family: Roboto, "Helvetica Neue", sans-serif;
}
.h6, h6 {
    font-size: 13px;
    line-height: 12px;
    letter-spacing: 0.15px;
    font-family: Roboto, "Helvetica Neue", sans-serif;
}
h5, h5 {
    font-size: 13px;
    letter-spacing: 0px;
    font-family: Roboto, "Helvetica Neue", sans-serif;
}
.h4, h4 {
    font-size: 18px;
    letter-spacing: 0.25px;
    font-family: Roboto, "Helvetica Neue", sans-serif;
}
.try{
    font-size: 35px;
    position: absolute;
    color: red;
    bottom: -1px;
    left: 12px;
}

.ts :

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { trigger, 
    state, 
    style, 
    animate, 
    transition, 
    keyframes } from '@angular/animations';


import {
  bounceInLeftOnEnterAnimation,
  flipInXOnEnterAnimation,
} from 'angular-animations';
export const slideOutLeft = [
    style({transform: 'translate3d(0, 0, 0)', offset: 0}),
    style({transform: 'translate3d(-150%, 0, 0)', opacity: 0, offset: 1}),
]
export const slideOutRight = [
    style({transform: 'translate3d(0, 0, 0)', offset: 0}),
    style({transform: 'translate3d(150%, 0, 0)', opacity: 0, offset: 1}),
]
export const slideOutDown = [
    style({transform: 'translate3d(0, 0, 0)', offset: 0}),
    style({transform: 'translate3d(0, -150%, 0)', opacity: 0, offset: 1}),
]
export const slideOutUp = [
    style({transform: 'translate3d(0, 0, 0)', offset: 0}),
    style({transform: 'translate3d(0, 150%, 0)', opacity: 0, offset: 1}),
]
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  animations: [
    trigger('cardAnimator', [
      transition('* => slideOutLeft', animate(1000, keyframes(slideOutLeft))),
      transition('* => slideOutRight', animate(1000, keyframes(slideOutRight))),
      transition('* => slideOutDown', animate(1000, keyframes(slideOutDown))),
      transition('* => slideOutUp', animate(1000, keyframes(slideOutUp))),
    ]),
    bounceInLeftOnEnterAnimation({ anchor: 'enter1' }),

  ]
})
export class AppComponent  {
  datas = [1,2,3,4,5,6,7];
  animationState: string;
  animationState1: string;
  ngOnInit() {
  }
  asd :any ;
  startAnimation(state,index) {
    console.log(state)
        console.log(index)

    this.asd = index;
    if (!this.animationState) {
      this.animationState = state;
    }
  }
  

  resetAnimationState() {
    this.animationState = '';
  }

}

app.module.ts:

代码语言:javascript
复制
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import {
  MatFormFieldModule,
  MatSelectModule,
  MatButtonModule,
  MatToolbarModule,
  MatInputModule,
  MatSidenavModule,
  MatIconModule,
  MatListModule
} from '@angular/material';
import { MatCardModule } from '@angular/material';

import { AppComponent } from './app.component';


@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    MatFormFieldModule,
    MatSelectModule,
    MatButtonModule,
    MatToolbarModule,
    MatInputModule,
    MatSidenavModule,
    MatCardModule,
    MatIconModule,
    MatListModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-18 07:27:26

更改这是如此后,将resetAnimationState更改为传递索引,并仅在animationStateindex为“slideOutLeft”或“slideOutRigth”时使用拼接

代码语言:javascript
复制
  resetAnimationState(index) {
    if (this.animationState[index]=='slideOutLeft' || this.animationState[index]=='slideOutRight')
      this.datas.splice(index,1)
      this.animationState.splice(index,1)
  }

stackblitz

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63462999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档