Angular PrimeNG骨架动画
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,这个框架可用于制作响应式网站,非常方便。在这篇文章中,我们将了解如何在Angular PrimeNG中使用骨架动画。我们还将了解代码中所使用的属性及其语法。
骨架组件作为要显示的材料的替身。可以使用animation="none"
属性将动画从骨架元素中移除。
Angular PrimeNG骨架动画属性:
- shape:它用于定义元素的形状。shape的可接受值是“矩形”和“圆形”。默认值是矩形。
- size。它用于定义圆和方元素的大小。默认值是null 。
- width: 用来定义元素的宽度。宽度的默认值是100%。
- height: 用来定义元素的高度。宽度的默认值是1rem。
- borderRadius。它用于定义元素的边界半径。它默认为主题的值。
- animation:它用于定义动画的类型。动画值可以是一个波浪或没有。动画的默认值是wave。
- styleClass。它用于定义元素的风格类别。宽度的默认值是null。
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:它将看起来像如下。
运行以下命令以查看输出。
ng serve --open
示例1:下面是说明使用Square和Circle骨架的Angular PrimeNG骨架动画的示例代码。
<h2 style="color: green;">GeeksforGeeks</h2>
<h5>Angular PrimeNG Skeleton Animation</h5>
<div class="p-d-flex">
<div>
Square with animation
<p-skeleton
shape="square"
size="10rem"
styleClass="p-mr-3 p-mt-2">
</p-skeleton>
</div>
<div>
Circle with animation
<p-skeleton
shape="circle"
size="10rem"
styleClass="p-mr-3 p-mt-2">
</p-skeleton>
</div>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {}
import { NgModule } from '@angular/core';
import { BrowserModule }
from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { ButtonModule } from 'primeng/button';
import { BadgeModule } from 'primeng/badge';
import { SkeletonModule } from 'primeng/skeleton';
import { TableModule } from 'primeng/table';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
SkeletonModule,
ButtonModule,
TableModule,
BadgeModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:
示例2:下面是另一个示例代码,说明了Angular PrimeNG Skeleton Animation的使用,使用Rectangle Skeleton与borderRadius。
<h2 style="color: green;">GeeksforGeeks</h2>
<h5>Angular PrimeNG Skeleton Animation</h5>
<p-skeleton
shape="rectangle"
borderRadius="1rem"
width="20rem"
height="5rem">
</p-skeleton>
<p-skeleton
shape="rectangle"
borderRadius="5rem"
width="10rem"
height="5rem"
styleClass="p-mt-3">
</p-skeleton>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {}
import { NgModule } from '@angular/core';
import { BrowserModule }
from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { ButtonModule } from 'primeng/button';
import { BadgeModule } from 'primeng/badge';
import { SkeletonModule } from 'primeng/skeleton';
import { TableModule } from 'primeng/table';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
SkeletonModule,
ButtonModule,
TableModule,
BadgeModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出: