一,改变浏览器默认的滚动条样式
::-webkit-scrollbar-track-piece { //滚动条凹槽的颜色,还可以设置边框属性
background-color:#f8f8f8;
}
::-webkit-scrollbar
::-webkit-scrollbar-thumb
::-webkit-scrollbar-thumb:hover {
background-color:#bbb;
}
二,给某个div .test1加滚动条样式
.test1::-webkit-scrollbar {
width:
8px;
}
.test1::-webkit-scrollbar-track {
background-color:red;
-webkit-border-radius: 2em;
-moz-border-radius: 2em;
border-radius:2em;
}
.test1::-webkit-scrollbar-thumb {
background-color:green;
-webkit-border-radius: 2em;
-moz-border-radius: 2em;
border-radius:2em;
}
三,malihu
malihu是一款高性能的滚动条美化jQuery插件。该滚动条美化插件支持水平和垂直滚动条,支持鼠标滚动,支持键盘滚动和支持移动触摸屏。
(1)
安装:
通过Bower或nmp来安装该滚动条美化插件
bower install malihu-custom-scrollbar-plugin
npm install malihu-custom-scrollbar-plugin
(2)
使用方法
使用该滚动条美化插件需要引入jQuery和jquery.mCustomScrollbar.concat.min.js以及jquery.mCustomScrollbar.css文件。
(3)
通过js来初始化
(4)
通过HTML来初始化
另外可以通过data-mcs-axis属性来设置是水平还是垂直滚动条,取值为x或y。
默认情况下该滚动条是垂直方向的滚动条,你可以通过配置参数将它设置为水平滚动条或两个方向上滚动条。
$(".content").mCustomScrollbar({
axis:"x" //水平滚动条
});
$(".content").mCustomScrollbar({
axis:"yx" //水平和垂直同时存在的滚动条
});