上次关于css滚动条样式的文章《美化css滚动条样式,就这么简单》,不够完美不兼容IE、火狐浏览器,但今天这篇文章可以完美解决这个问题,用到了jquery插件jquery.mCustomScrollbar,还是挺好用的,样式主题多够我们用了,也可以自定义样式。
1.使用方法:
1)先引入jquery插件jquery.mCustomScrollbar样式和它的js以及jquery
<link rel="stylesheet" href="css/jquery.mCustomScrollbar.min.css" />
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.mCustomScrollbar.concat.min.js"></script>
2)以盒子box为例加上css滚动条
$(".box").mCustomScrollbar();
2.例子代码如下:
<!Doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>css滚动条样式,jquery插件完美解决ie火狐不兼容问题</title>
<link rel="stylesheet" href="css/jquery.mCustomScrollbar.min.css" />
<style type="text/css">
.box{
width: 600px;
height: 400px;
margin: 100px auto;
border: 1px solid #000;
border-right: 0;
}
.main{
overflow-x: hidden;
overflow-y: auto;
color: #000;
font-size: 16px;
height: 100%;
}
.main p{height:300px;}
</style>
</head>
<body>
<div class="box">
<div class="main">
<p>内容1</p>
<p>内容2</p>
<p>内容3</p>
</div>
</div>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.mCustomScrollbar.concat.min.js"></script>
<script>
(function($){
$(window).on("load",function(){
$(".box").mCustomScrollbar({
//官网的滚动条主题
theme:"3d-thick-dark"
});
});
})(jQuery);
</script>
</body>
</html>
查看效果演示:http://tangjiusheng.com/jQuery/jquery.mCustomScrollbar/
3.例子说明:
1)使用了官网的滚动条主题“3d-thick-dark”
2)可以根据你喜好选择的你的主题,点击查看:官网的滚动条主题
3)这个插件只兼容IE8以上
4.最后:
更多参数设置,可以去官网了解下,插件jquery.mCustomScrollbar官网地址:
http://manos.malihu.gr/jquery-custom-content-scroller/
原文地址:http://tangjiusheng.com/jQuery/160.html
温馨提示:加下微信【yes2016yes99】将免费分享给你一份web前端开发资料,一起交流学习前端开发,一起进步!