Last active
November 1, 2016 07:42
-
-
Save JonathanDn/37b416602bfdaf5e192f7cc42526ea39 to your computer and use it in GitHub Desktop.
Angular 2 Malihu Custom Scrollbar Implmentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app-scrollbar --> | |
<div class="alert-items-wrapper" app-scrollbar> | |
<div *ngFor="let item of items">{{item.name}}</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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... */ | |
/* ---------------------------------------- */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.