
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
ngx-malihu-scrollbar
Advanced tools
Angular scrollbar customization using Malihu jQuery Custom Scrollbar plugin
Angular Malihu jQuery Custom Scrollbar directive and service.
Malihu jQuery Custom Scrollbar is a highly customizable scrollbar plugin that include vertical and/or horizontal scrollbar(s), adjustable scrolling momentum, mouse-wheel (via jQuery mousewheel plugin), keyboard and touch support, ready-to-use themes and customization via CSS, RTL direction support, option parameters for full control of scrollbar functionality, methods for triggering actions like scroll-to, update, destroy etc., user-defined callbacks and more.
Use the following command to add ngx-malihu-scrollbar library to your package.json file. Note that jQuery will automatically be downloaded as a dependency.
npm install ngx-malihu-scrollbar --save
You will need to add Malihu Custom Scrollbar javascript and css files with jQuery to your application.
If you are using Angular CLI you can follow the example below...
"styles": [
"src/styles.scss",
+ "node_modules/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.css"
],
"scripts": [
+ "node_modules/jquery/dist/jquery.min.js",
+ "node_modules/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js"
],
{
"compilerOptions": {
...
"types": [
+ "jquery",
+ "mcustomscrollbar"
]
},
...
}
You must import MalihuScrollbarModule inside your module to be able to use malihu-scrollbar directive or MalihuScrollbarService.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
+ import { MalihuScrollbarModule } from 'ngx-malihu-scrollbar';
import { HomeComponent } from './home.component';
@NgModule({
imports: [
CommonModule,
+ MalihuScrollbarModule.forRoot(),
],
declarations: [HomeComponent],
})
ngx-malihu-scrollbar provides both a directive and a service to apply the custom scrollbar on your HTML element.
For a complete list of available customization options please refer to the original Malihu Custom Scrollbar documentation.
You can use malihu-scrollbar directive directly on an HTML element and provide plugin options using scrollbarOptions input property.
public scrollbarOptions = { axis: 'yx', theme: 'minimal-dark' };
<div malihu-scrollbar [scrollbarOptions]="scrollbarOptions">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...
</div>
Alternatively, you can initialize scrollbar customizations using MalihuScrollbarService by providing either a string selector, a jQuery object or an HTML element along with the scrolling options.
The service also provide access to other Malihu Custom Scrollbar methods such as scrollTo, stop, update, disable and destroy.
constructor(
private mScrollbarService: MalihuScrollbarService,
) { }
ngAfterViewInit() {
this.mScrollbarService.initScrollbar('#myElementId', { axis: 'y', theme: 'dark-thick', scrollButtons: { enable: true } });
}
ngOnDestroy() {
this.mScrollbarService.destroy('#myElementId');
}
Of course, the scrollbars are fully customizable. You can easily clone an existing theme and modify the CSS to apply your own styling. Follow the instructions provided on the original Malihu Custom Scrollbar Plugin documentation for more details.
The "custom-theme" example on the bottom of the demo is a good example of customization where I created a my own "metro" theme.
Using MalihuScrollbarService you can target document.body to apply customization to the body scrollbar.
Note that this will automaticaly add some specific CSS to the
<body>element that is needed to allow scrollbar customization.
import { MalihuScrollbarService } from 'ngx-malihu-scrollbar';
constructor(
private mScrollbarService: MalihuScrollbarService,
) { }
ngOnInit() {
this.mScrollbarService.initScrollbar(document.body, { axis: 'y', theme: 'dark-3' });
}
You can find the demo source code inside the demo directory.
The following commands will clone the repository, install npm dependencies and serve the application @ http://localhost:4200
git clone https://github.com/jfcere/ngx-malihu-scrollbar.git
npm install
ng serve
Contributions are always welcome, just make sure that ...
Licensed under MIT.
FAQs
Angular scrollbar customization using Malihu jQuery Custom Scrollbar plugin
We found that ngx-malihu-scrollbar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.