Skip to content

Instantly share code, notes, and snippets.

@JonathanDn
Last active November 1, 2016 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanDn/37b416602bfdaf5e192f7cc42526ea39 to your computer and use it in GitHub Desktop.
Save JonathanDn/37b416602bfdaf5e192f7cc42526ea39 to your computer and use it in GitHub Desktop.
Angular 2 Malihu Custom Scrollbar Implmentation
import {Directive, ElementRef, Input, Renderer} from '@angular/core';
import 'jquery-mousewheel';
import 'malihu-custom-scrollbar-plugin';
@Directive({
selector: "[app-scrollbar]"
})
export class ScrollbarDirective {
@Input('axis') axis: string = 'y';
constructor(el: ElementRef, renderer: Renderer) {
let axis: "x"|"y"|"yx" = <"x"|"y"|"yx"> this.axis;
$(function() {
$(el.nativeElement).mCustomScrollbar({
theme: "mnr-dark",
axis: axis
})
});
}
}
<!-- app-scrollbar -->
<div class="alert-items-wrapper" app-scrollbar>
<div *ngFor="let item of items">{{item.name}}</div>
</div>
/*Scrollbar styles*/
/* theme: "dark" */
.mCS-mnr-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{ background-color: $scrollbar_color; }
.mCS-mnr-dark.mCSB_scrollTools .mCSB_draggerRail{ background-color: white; }
/* and so on... */
/* ---------------------------------------- */
@JonathanDn
Copy link
Author

JonathanDn commented Oct 30, 2016

Angular 2 - malihu custom scrollbar fully functional and working implementation:

1.Write the directive and make sure when you use the malihu plugin and jquery to do it like so:
$(function() {
$(el.nativeElement).mCustomScrollbar({
theme: "mnr-dark",
axis: axis
})
});

2.Provide your directive and declare it in an index.ts file like so:
import {ScrollbarDirective} from './scrollbar.directive';

export default [
ScrollbarDirective
];
2.1.this should be declared and provided within your shared.module.ts module according.
3.Feel free to use the scrollbar selector of the directive attribute: "app-scrollbar" wherever needed and enjoy :)
*This implementation does not support dragging items over the scrollbar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment