ngx-sticky-navbar
ngx-sticky-navbar is an Angular 6+ component that wrapps your navigation and it has some cool features.
Navbar's Sensitivity
You can set sensitivity of scroll speed when to show/hide navbar. Example of sensitivity configuration:
settings: Settings =;
To setup sensitivitity You can use defined sensitivities (more details) or just pass a number. Greater number lowers sensitivity (0 = high sensitivity, 100 = low sensitivity).
Navbar's Offset Top
Everytime user scroll back to the top, the navbar becomes visible. You can configure the top offset when it should appear. There two ways:
- Setup offset top manually
settings: Settings =;
- Setup offset top automatically. It will set top property automatically and dynamically to height of navbar element.
settings: Settings =;
Navbar's Spacer
As ngx-sticky-navbar uses CSS position:fixed, so element wrapped by this component doesn't affect DOM height. You can compensate it by creating Spacer with height manually or automatically set at selected DOM element. To create Spacer You need three properties: height or autoHeight, Type, Element (more details).
- Manual height of Spacer:
ngAfterViewInit ; this.navbarService.mergeSettingObjectthis.settings; }
- Automatic height of Spacer:
ngAfterViewInit
Navbar's Configuration
- Pass settings object via property binding (required usage) link
- Dynamically updating global variable settings object link
Note
Component requires Angular and Rxjs version >= 6.0.0.
Demo
Check the link
Usage
Install ngx-sticky-navbar
- npm:
$ npm install ngx-sticky-navbar
- yarn:
$ yarn add ngx-sticky-navbar
import NgxStickyNavbarModule
;
Use ngx-sticky-navbar
;
Use Spacer (example extends example above)
;
HTML
...
Spacer HTML
... <!-- Place where You wanna add Spacer -->
Enums / Models
Settings
Defined Sensitivity
Navbar State
Spacer Types
Service
public initialSettings: Settings // default initial settings;public settings: Settings // global settings used by all elements of component // NgxStickyNavbarService.settings = global settings// Method sets global settings but without triggering Subject<Settings>.// Used only to change global settings variable.setGlobalSettingssettings: Settings: void // Method uses setGlobalSettings() and triggers Subject<Settings>// to update global settings state in every// component's element (service/directibe/component).mergeSettingObjectsettings: Settings: void
Dynamically Update Settings:
;
or reasign initialSettings
Contributing
- Fork repo.
npm install / yarn
.- Make your changes.
- Add your tests.
npm run test / yarn start test
.npm run build / yarn start build
.- After all tests are passing.
- Commit, push, PR.
License
Released under the terms of MIT License.