Angular PrimeNG Scroll Top Window
Angular PrimeNG是一个用于angular应用程序的UI组件目录。它由一系列的UI组件组成,有助于制作快速和可扩展的网站。在这篇文章中,我们将看到Angular PrimeNG中的ScrollTop Window。
ScrollTop组件在用户向上滚动到某一滚动位置后显示,用于快速进入页面顶部。ScrollTop窗口应用于整个页面,用于向下滚动页面,以显示ScrollTo组件。
语法:
<p-scrollTop icon="..." [threshold]="..."></p-scrollTop>
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new newapp
第2步:在创建你的项目文件夹即newapp后,使用以下命令移动到它。
cd newapp
第3步:在你的项目目录中安装PrimeNG和PrimeIcons。
npm install primeng --save
npm install primeicons --save
项目结构:完成安装后,项目结构将如下所示。
Project Structure
例子1:这是一个基本的例子,说明了如何使用scrollTop组件倾听窗口的滚动。
<h1 style="color:green">GeeksforGeeks</h1>
<h3>Angular PrimeNG ScrollTop Window</h3>
<div style="font-size: 20px;">
<h2> About GeeksforGeeks </h2>
<p>
GeeksforGeeks is a computer
science portal for geeks.
It offers thousands of written
articles on various computer science
topics. Some of the topics are
listed below:
</p>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
<li>Php</li>
<li>Bootstrap</li>
<li>NodeJS</li>
<li>ReactJS</li>
<li>AngularJS</li>
<li>ExpressJS</li>
<li>Tailwind</li>
<li>Bulma</li>
<li>Foundation</li>
<li>React Desktop</li>
<li>jQuery UI</li>
<li>jQuery Mobile</li>
<li>Typescript</li>
<li>p5.js</li>
<li>Tensorflow.js</li>
<li>Python</li>
<li>C/C++</li>
<li>C/C++</li>
<li>DSA</li>
<li>Java</li>
<li>Ruby</li>
<li>Machine Learning</li>
<li>Database Management System</li>
<li>Compiler Design</li>
</ul>
</div>
<!-- ScrollTop Element targeting window by default -->
<p-scrollTop></p-scrollTop>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styles: []
})
export class AppComponent { }
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { ScrollTopModule } from 'primeng/scrolltop';
import { ScrollPanelModule } from 'primeng/scrollpanel';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
ScrollTopModule,
ScrollPanelModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
输出:
例子2:这是滚动顶端窗口的另一个例子,我们改变了滚动顶端组件的图标和阈值。
<h1 style="color:green">GeeksforGeeks</h1>
<h3>Angular PrimeNG ScrollTop Window</h3>
<div style="font-size: 20px;">
<h2> About GeeksforGeeks </h2>
<p>
GeeksforGeeks is a computer
science portal for geeks.
It offers thousands of written
articles on various computer science
topics. Some of the topics are
listed below:
</p>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
<li>Php</li>
<li>Bootstrap</li>
<li>NodeJS</li>
<li>ReactJS</li>
<li>AngularJS</li>
<li>ExpressJS</li>
<li>Tailwind</li>
<li>Bulma</li>
<li>Foundation</li>
<li>React Desktop</li>
<li>jQuery UI</li>
<li>jQuery Mobile</li>
<li>Typescript</li>
<li>p5.js</li>
<li>Tensorflow.js</li>
<li>Python</li>
<li>C/C++</li>
<li>C/C++</li>
<li>DSA</li>
<li>Java</li>
<li>Ruby</li>
<li>Machine Learning</li>
<li>Database Management System</li>
<li>Compiler Design</li>
</ul>
</div>
<!-- ScrollTop Element targeting window by default -->
<p-scrollTop icon="pi pi-angle-double-up"
[threshold]="100">
</p-scrollTop>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styles: []
})
export class AppComponent { }
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { ScrollTopModule } from 'primeng/scrolltop';
import { ScrollPanelModule } from 'primeng/scrollpanel';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
ScrollTopModule,
ScrollPanelModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
输出: