7.0.0 • Published 4 months ago

ngx-scrolltop v7.0.0

Weekly downloads
406
License
MIT
Repository
github
Last release
4 months ago

npm version Join the chat at https://gitter.im/ngx-scrolltop/Lobby npm.io volkswagen status

Lightweight, Material Design inspired button for scroll-to-top of the page. No dependencies. Pure Angular!

✓ Angular 10, Ivy and SSR compatible

Just hit the button to smoothly scroll back to the top of the page. Here's the demo.

  • Lightweight (~2 kB gzipped)
  • No dependencies!
  • Material Design inspired
  • @angular/material compatible (example)
  • Angular 5+ compatible
  • Component or directive way
  • Smoothly animated
  • a11y ready
  • Highly customizable options...

Demo animation

Demo (example)

Watch this demo page

Or play with it live on stackblitz.com/edit/ngx-scrolltop

Install

Automatically (recommended) 🚀

ng add ngx-scrolltop

Everything's done! (module imported and all settings automatically set in your project.)

Now just see some options and examples.

Manually (old-school) 🛠

Via yarn or npm

yarn add ngx-scrolltop # npm install ngx-scrolltop --save

Setup (manually)

...
+ import { NgxScrollTopModule } from 'ngx-scrolltop';
...

@NgModule({
  imports: [
    ...
+   NgxScrollTopModule
  ],
  ...
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

Component way (default)

In app.component.html you just need to add your new button. Usually at the end of file.

<ngx-scrolltop></ngx-scrolltop>

Directive way

Your custom element somewhere in you application...

Important: (no style applied, everything is up to you. Of course I recommend position: fixed, ...)

<span ngxScrollTop class="my-custom-element-with-my-style__no-lib-style-applied-here">
  ↑ My Custom Element. ↑
</span>

Options

Component

OptionTypeDefaultDescription
mode'smart' | 'classic''classic'Smart mode shows button only when you scroll more than two screens down and then you will try to go back to top. Classic mode shows button immediately when you scroll at least one screen down.
backgroundColorstring#212121Background color (you can use all values for backgroud-color css property). You can override theme color
symbolColorstring#fafafaSymbol color (you can use all values for fill svg property). You can override theme color
sizenumber40Button size in pixels. (Symbol will be resized automatically)
symbolstringYou can use utf8 chars for customizing symbol. For example:
position'left' | 'right''right'Left or right, that is the question...
themeNgxScrollTopTheme'gray'Material color themes

Directive

OptionTypeDefaultDescription
ngxScrollTopMode'smart' | 'classic''classic'Smart mode shows button only when you scroll more than two screens down and then you will try to go back to top. Classic mode shows button immediately when you scroll at least one screen down.

Examples

Advanced example (component)

app.component.html

<ngx-scrolltop
  [size]="50"
  backgroundColor="#33691e"
  symbolColor="#fff"
  symbol="↑"
  mode="smart"
  position="left"
  theme="pink"
>
</ngx-scrolltop>

Angular Material example (directive)

@angular/material required

app.component.html

<button
  ngxScrollTop
  [ngxScrollTopMode]="'smart'"
  class="my-custom-style"
  color="primary"
  mat-mini-fab
>
  top
</button>

app.component.scss

.my-custom-style {
  position: fixed;
  right: 20px;
  bottom: 20px;
}

Dependencies

No dependencies! Pure Angular.

Donation

If this project have helped you save time please consider making a donation for some 🍺 or 🍵 ;)

License

Copyright © 2020 Lukas Bartak

Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)

All contents are licensed under the MIT license.

17.0.0-next.0

4 months ago

7.0.0

4 months ago

7.0.1-beta.2

4 months ago

7.0.0-next.0

4 months ago

7.0.0-beta.0

4 months ago

6.0.0

11 months ago

6.0.0-next.0

11 months ago

5.1.0

1 year ago

5.1.0-next.0

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

5.0.0-next.1

1 year ago

5.0.0-next.0

1 year ago

4.3.0

2 years ago

4.3.0-beta.0

2 years ago

4.2.0

2 years ago

3.1.0-next.1

2 years ago

3.1.0-next.0

2 years ago

3.1.0-next.2

2 years ago

4.0.0-alpha.1

2 years ago

4.0.0

2 years ago

4.0.0-next.0

2 years ago

3.1.0

2 years ago

4.1.0

2 years ago

4.1.2

2 years ago

3.0.0-next.0

2 years ago

3.0.0

2 years ago

12.0.0-beta.1

3 years ago

12.0.0-beta.0

3 years ago

3.0.0-beta.4

3 years ago

2.4.0

3 years ago

3.0.0-beta.1

3 years ago

3.0.0-beta.0

3 years ago

3.0.0-beta.3

3 years ago

3.0.0-beta.2

3 years ago

2.4.0-rc.0

3 years ago

2.4.0-beta.0

3 years ago

2.3.1

3 years ago

2.3.1-beta.0

3 years ago

2.4.0-beta.3

3 years ago

2.4.0-beta.1

3 years ago

2.3.0-beta.0

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.2.0-beta.0

3 years ago

2.1.0

3 years ago

2.1.0-beta.0

3 years ago

2.0.3

3 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0-rc.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago

1.0.0-rc.1

4 years ago

0.8.4

4 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

4 years ago

7.0.0-beta.3

4 years ago

7.0.0-beta.2

4 years ago

0.8.3

4 years ago

7.0.0-beta.1

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.8

4 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.5-rc.3

4 years ago

0.5.4

4 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.1

5 years ago