简介

此插件是 Malihu jQuery Scrollbar 为了在 Angular2+ 环境下使用,封装的一个ts的版本。提供directiveservice

从安装量来看,它比不过 perfect-scrollbar,所以我最后也没用它。但是也记录一下用法,万一以后要用呢!

安装

npm install ngx-malihu-scrollbar --save
我当时安装的版本是 `7.0.0`。

添加需要的css和script

这个插件是依赖jQuery的。

_angular-cli.json中添加

    "styles": [
"../src/scss/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"
],

在tsconfig.app.json添加

{
"compilerOptions": {
...
"types": [
+ "jquery",
+ "mcustomscrollbar"
]
},
...
}

使用

在根module中引入

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],
})

模板中使用

<ul *ngIf="nodeList.length" class="indented mTop scroll"  [style.max-height.px]="treeContentHeight" malihu-scrollbar [scrollbarOptions]="scrollbarOptions">
<li class="no_line" *ngFor="let node of nodeList"></li>
</ul>

component中配置options

+ import { MalihuScrollbarService } from 'ngx-malihu-scrollbar';

+ public scrollbarOptions: any = { axis: 'y', theme: 'my-theme'};
constructor(
private _router: Router,
private mScrollbarService: MalihuScrollbarService,
) { } // 更新 setTreeContentHeight() {
...
// caculate height // update scroll
this.mScrollbarService.update('#scrollContainer'); }

自定义的主题样式

在 styles.css 中自定义样式

.mCS-my-theme.mCSB_scrollTools{
.mCSB_dragger{
.mCSB_dragger_bar{ background-color: #DEDEE4 !important; }
}
.mCSB_draggerRail{ background-color: transparent !important; }
}

使用感受:没有perfect-scrollbar流畅,每次滚动条出现时,会先出现浏览器的默认滚动条,然后才渲染出自定义的滚动条,不完美。故,弃用之~

Angular5 自定义scrollbar样式之 ngx-malihu-scrollbar的更多相关文章

  1. Android必知必会-自定义Scrollbar样式

    如果移动端访问不佳,请使用–>GitHub版 背景 设计师给的设计图完全依照 IOS 的标准来的,导致很多细节的控件都得自己重写,最近的设计图中有显示滚动条,Android 默认的滚动条样式(带 ...

  2. scrollbar样式设置

    转载:https://segmentfault.com/a/1190000012800450?utm_source=tag-newest author:specialCoder 一 前言 在CSS 中 ...

  3. CSS3:scrollbar样式设置

    CSS3:scrollbar样式设置 1. 设置出现滚动条的方式 overflow:scroll --- x和y方向都会出现滚动条 或者 overflow-x:scroll --- 只有x方向出现滚动 ...

  4. jQuery自定义滚动条样式插件mCustomScrollbar

    如果你构建一个很有特色和创意的网页,那么肯定希望定义网页中的滚动条样式,这方面的 jQuery 插件比较不错的,有两个:jScrollPane 和 mCustomScrollbar. 关于 jScro ...

  5. WPF 自定义滚动条样式

    先看一下效果: 先分析一下滚动条有哪儿几部分组成: 滚动条总共有五部分组成: 两端的箭头按钮,实际类型为RepeatButton Thumb 两端的空白,实际也是RepeatButton 最后就是Th ...

  6. 自定义滚动条样式-transition无效

    问题 需求是自定义滚动条样式,然后2秒内无操作隐藏滚动条. 2s内隐藏比较麻烦,不能用css实现,只能监听容器的touch事件,然后给滚动条加个opacity: 0的class. .class::-w ...

  7. Siteserver-stl:searchOutput(搜索结果)自定义显示样式

    stl:searchOutput 自定义显示样式 自定义搜索提交表单需要在<stl:searchOutput>中嵌入显示搜索结果的标签,必须包含的标签 有<stl:pageConte ...

  8. 自定义plain 样式的 tableview,模拟器上不显示分割线,真机上却显示分割线.

    一, 经历 1> 自定义plain 样式的 tableview,模拟器上不显示分割线,真机上却显示cell 下面的分割线. 2> 尝试使用表格的separatorStyle属性,尝试失败. ...

  9. Winform自定义窗体样式,实现标题栏可灵活自定义

    最近在编写C/S结构应用程序时,感觉窗体的标题栏样式太死板了,标题文字不能更改大小.颜色.字体等,按钮不能隐藏等问题,在网上也查找了许多相关的资料,没有找到合适的解决方案,发现许多人也在寻求这个问题, ...

  10. Android设置选项开发及自定义Preference样式

    一个完整的Android应用程序都应该提供选项(或者叫偏好设置等等)让用户对APP的表现形式能够进行设置,比如说是否加入用户体验计划,或者是否自动升级.定时提醒.开启自启动.后台运行等等.提供一个好的 ...

随机推荐

  1. 当心JavaScript奇葩的逗号表达式

    看看下面的代码输出什么? let a = 2; switch (a) { case (3, 2, 5): console.log(1); break case (2, 3, 4): console.l ...

  2. springmvc手动渲染jsp

    因为需要MockHttpServletResponse对象来得到输出的内容,要引入的包 <dependency> <groupId>org.springframework< ...

  3. Springboot设置session超时时间

    按优先级高到低说: 第一种: spring boot 启动类里面: package com.mycenter; import org.mybatis.spring.annotation.MapperS ...

  4. OpenCV笔记(2)(高斯平滑、腐蚀和膨胀、开闭运算、礼帽和黑帽、Sobel及其他算子)

    一.高斯平滑(模糊) def gaussian_blur(image): # 设置ksize来确定模糊效果 img = cv.GaussianBlur(image, (5, 5), 0) cv.ims ...

  5. Ubuntu:打开JPEG文件错误(Not a JPEG File: starts with 0x52 0x49)

    Ubuntu 16.04.4,造冰箱的大熊猫@cnblogs 2018/7/12 近日下载资料时得到一些后缀为jpg的图片文件.这些图片在手机上能够正常预览,但在Ubuntu的文件管理器中无法预览这些 ...

  6. PHP 下载+安装

    1.官网下载 官网地址:http://PHP.net/ 地址:http://download.csdn.NET/detail/anndy_/9494632 官网手册:https://secure.ph ...

  7. Cqoi2017试题泛做

    Day1 4813: [Cqoi2017]小Q的棋盘 树形背包DP. #include <cstdio> #define maxn 110 #define R register #defi ...

  8. ant design 的表格默认选中

    在使用 ant design 的表格时候使用默认选中项, 需要配置的 Table 的 rowSelection const rowSelection = { type: 'checkbox', get ...

  9. #pragma once vs #ifndef

    最后编辑: 2019-11-20 #pragma once 是一个非标准但被广泛支持的预处理符号, 其主要作用是防止文件重复引入问题. 在头文件中,可以定义 #pragma once 或者 #ifnd ...

  10. 分布式-信息方式-ActiveMQ基础

    ActiveMQ简介 ActiveMQ是什么ActiveMQ是Apache推出的,一款开源全支持JMS.1和J2EE1.4范的JMS Provider实现的信息中间件.(message oriente ...