Angular PrimeNG Ripple样式设计
Angular PrimeNG是一个用于Angular应用程序的UI组件库。它为各种任务提供了许多预建的主题和UI组件,如输入、菜单、图表、按钮等。在这篇文章中,我们将看到Angular PrimeNG Ripple Styling。
波纹组件用于在主元素上应用波纹效果动画。波纹效果的颜色可以通过改变 “p-ink “类的背景属性来定制。
语法:
<div pRipple class="green">....</div>
// In CSS
.p-ripple.green .p-ink {
background: rgba(0, 255, 0, .3);
}
创建Angular应用程序并安装模块:。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步:最后,在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:在完成上述步骤后,项目结构将看起来像这样。
Project Structure
运行以下命令:
ng serve --open
例子1:在这个例子中,我们展示了默认和红色的波纹。
<div style="text-align: center">
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Ripple Styling</h4>
<div class="cards flex justify-content-center mt-5">
<p-card
pRipple
class="default"
header="Deafult Ripple"
[style]="{'width': '300px', 'margin-right': '20px'}">
<p>Ripple Component Demo</p>
</p-card>
<p-card
pRipple
class="red"
header="Red Ripple"
[style]="{'width': '300px'}">
<p>Ripple Component Demo</p>
</p-card>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styles: [
`
.cards{
user-select: none;
}
`
]
})
export class AppComponent implements OnInit{
constructor(private primengConfig: PrimeNGConfig) { }
ngOnInit() {
this.primengConfig.ripple = true;
}
}
import { NgModule } from '@angular/core';
import { BrowserModule }
from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { CardModule } from 'primeng/card';
import { RippleModule } from 'primeng/ripple';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
CardModule,
RippleModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
.default .p-card-body{
background-color: green;
padding: 0;
color: white;
}
.p-ripple.red .p-ink {
background: rgba(255, 0, 0, .3);
}
输出:
例子2:在这个例子中,我们将波纹的颜色改为绿色和蓝色。
<div style="text-align: center">
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Ripple Styling</h4>
<div class="cards flex justify-content-center mt-5">
<p-card
pRipple
class="green"
header="Green Ripple"
[style]="{'width': '300px', 'margin-right': '20px'}">
<p>Ripple Component Demo</p>
</p-card>
<p-card
pRipple
class="blue"
header="Blue Ripple"
[style]="{'width': '300px'}">
<p>Ripple Component Demo</p>
</p-card>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styles: [
`
.cards{
user-select: none;
}
`
]
})
export class AppComponent implements OnInit{
constructor(private primengConfig: PrimeNGConfig) { }
ngOnInit() {
this.primengConfig.ripple = true;
}
}
import { NgModule } from '@angular/core';
import { BrowserModule }
from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { CardModule } from 'primeng/card';
import { RippleModule } from 'primeng/ripple';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
CardModule,
RippleModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
- styles.css:
.p-ripple.green .p-ink {
background: rgba(0, 255, 0, .3);
}
.p-ripple.blue .p-ink {
background: rgba(0, 0, 255, .3);
}
输出: