一些元素,如按钮,Ionic 2 已经有本地水波纹效果。其他元素,如卡片则没有。我该如何为任意 Ionic 2 元素添加水波纹效果支持?
一些元素,如按钮,Ionic 2 已经有本地水波纹效果。其他元素,如卡片则没有。我该如何为任意 Ionic 2 元素添加水波纹效果支持?
<button ion-item>
<ion-item style="background: rgba(0,0,0,0);">Content</ion-item>
</button>
div
元素,并带有button-effect
类。此外,容器必须具有tappable
属性,并被样式化为position: relative; overflow: hidden
。import {Directive, ElementRef, Host, Renderer2} from '@angular/core';
@Directive({
selector: '[m-ripple-effect]',
host: {
'tappable': '',
'role': 'button',
'style': 'position: relative; overflow: hidden'
}
})
export class RippleEffectDirective {
constructor(@Host() host: ElementRef, renderer: Renderer2) {
const div = renderer.createElement('div');
renderer.addClass(div, 'button-effect');
renderer.appendChild(host.nativeElement, div);
}
}
button
元素,你仍然可以使用ion-item指令:<ion-item (click)="viewArticle()"></ion-item>
致:
<button ion-item (click)="viewArticle()"></button>
以下是基于Bartosz Kosarzycki的回答的更完整示例:
<ion-list>
<button ion-button style="height: auto!important;width: 100%" clear >
<ion-item style="background: rgba(0,0,0,0);">
<ion-icon name="car" item-left></ion-icon>
<h1>Title 1</h1>
<p>Subtítulo</p>
<ion-icon name="person" item-right></ion-icon>
</ion-item>
</button>
<button ion-button style="height: auto!important;width: 100%" clear>
<ion-item style="background: rgba(0,0,0,0);">
<ion-icon name="person" item-left></ion-icon>
<h1>Title 2</h1>
<p>Subtítulo</p>
<ion-icon name="car" item-right></ion-icon>
</ion-item>
</button>
</ion-list>
对于IONIC 4,您现在可以像这样使用:
确保您的div位置是相对的。
<div
ion-activatable
class="ion-activatable"
style="position:relative;height:100px;width:100%;background:blue;">
<ion-ripple-effect></ion-ripple-effect>
Content here...
</div>
:)