在Angular中实现中间位置的自定义滚动条
npm install ngx-scrollbar --save
import { NgxScrollbarModule } from 'ngx-scrollbar';
@NgModule({
imports: [
NgxScrollbarModule
]
})
在样式文件中设置.outer类的样式为:
.outer {
height: 300px; /* 高度自定义 */
overflow-y: hidden;
display: flex;
justify-content: center;
}
::ng-deep .scrollable-content {
/* inner content styles */
height: 100%;
max-height: 100%;
overflow-y: auto;
margin-right: -16px; /* 确保始终有滚动条 */
padding-right: 16px;
}
HTML模板:
样式文件:
.outer {
height: 300px;
overflow-y: hidden;
display: flex;
justify-content: center;
}
::ng-deep .scrollable-content {
height: 100%;
max-height: 100%;
overflow-y: auto;
margin-right: -16px;
padding-right: 16px;
}