提问者:小点点

在行点击时为垫子表添加角材料波纹效果


我使用的是角材料V6。只要单击mat-table中的一行,我就想添加一个涟漪效果。

HTML:

<table mat-table [dataSource]="this.projectsList" class="mat-elevation-z8">

  <ng-container matColumnDef="id">
    <th mat-header-cell *matHeaderCellDef>ID</th>
    <td mat-cell *matCellDef="let project">{{project.id}}</td>
  </ng-container>

  <ng-container matColumnDef="title">
    <th mat-header-cell *matHeaderCellDef>Title</th>
    <td mat-cell *matCellDef="let project">{{project.title}}</td>
  </ng-container>

  <tr mat-header-row *matHeaderRowDef="this.displayColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: this.displayColumns"></tr>

</table>

SCSS:

table {
  width: 90vw;
  margin-top: 1%;
  margin-left: auto;
  margin-right: auto;
}

.mat-row:hover {
  background: rgba(0, 0, 0, 0.04);
}

模块导入:

AppRoutingModule,
BrowserModule,
BrowserAnimationsModule,
MatToolbarModule,
MatSidenavModule,
MatButtonModule,
MatCheckboxModule

自定义主题:

@import '~@angular/material/theming';
@import './palette.scss';
// Plus imports for other components in your app.

// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// **Be sure that you only ever include this mixin once!**
@include mat-core();

// Define the default theme (same as the example above).
$light-primary-blue:    mat-palette($primary-blue);
$light-accent-purple:   mat-palette($accent-purple);
$light-theme:           mat-light-theme($light-primary-blue, $light-accent-purple);

// Include the default theme styles.
@include angular-material-theme($light-theme);

// Define an alternate dark theme.
$dark-primary: mat-palette($primary-blue);
$dark-accent:  mat-palette($accent-purple);
$dark-theme:   mat-dark-theme($dark-primary, $dark-accent);

// Include the alternative theme styles inside of a block with a CSS class. You can make this
// CSS class whatever you want. In this example, any component inside of an element with
// `.dark` will be affected by this alternate dark theme instead of the default theme.
.dark {
  @include angular-material-theme($dark-theme);
}

我找不到任何关于向表中添加涟漪效果的文档,但我看到过几个Stackblitz实例,它们对行单击具有涟漪效果。我试图照搬他们正在做的事情,但没有成功。


共1个答案

匿名用户

如下所示修改您的td元素。

<table mat-table [dataSource]="this.projectsList" class="mat-elevation-z8">

  <ng-container matColumnDef="title">
    <th mat-header-cell *matHeaderCellDef>Title</th>
    <td mat-cell *matCellDef="let project">
      <div class='mat-ripple-wrapper' matRipple>
        {{project.title}}
      </div> 
    </td>
  </ng-container>

</table>

风格

.mat-ripple-wrapper{
   position: relative;
}

mat-ripple指令在单击触发器元素后创建一个div。如果触发器元素放在行上,它就会掉在不合适的地方。最好的方法是将td数据包装在div中,并在该div上添加指令以包含动态生成的div。

相关问题