滚动条美化

下载jquery.mCustomScrollbar包可以去github上搜。

将jquery.mCustomScrollbar的js与css文件导入项目中。

在这里插入图片描述

接下来在html页面导入用到的js与css(bootstrap,jquery,mCustomScrollbar)。

<link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}"> 
<link rel="stylesheet" th:href="@{/plugins/jquery-mcustomscrollbar/css/jquery.mCustomScrollbar.css}">


<script th:src="@{/js/jquery-3.6.0.min.js}"></script>
<script th:src="@{/bootstrap/js/bootstrap.bundle.min.js}"></script>
<script th:src="@{/plugins/jquery-mcustomscrollbar/js/jquery.mCustomScrollbar.js}"></script>

编写html例子

<!--
一:添加bootstrap样式增加滚动条
其实只要在 相关模块的  class属性中,再加上  pre-scrollable 即可。
例如是在<div >中添加pre-scrollable:
```html
<div class="pre-scrollable">
```
二:通过设置overflow增加滚动条
```html
<div style=" overflow:scroll; width:400px; height:400px;”></div>
```
记住宽和高一定要设置噢,否则不成的,不过在不超出时,会有下面的滚动条,所以不是最好的选择.
```html
<div style=" overflow-y:auto; overflow-x:auto; width:400px; height:400px;”></div>
```
记住宽和高一定要设置噢,否则不成的.这样比较好的是,在宽和高不超出时,只是一条线.
三:直接为div指定overflow属性为auto即可,但是必须指定div的高度,如下:
```html
<div style="position:absolute; height:400px; overflow:auto"></div>
```
如果要出现水平滚动条,则: overflow-x:auto
同理,垂直滚动条为: overflow-y:auto
如果该div被包含在其他对象例如td中,则位置可设为相对:position:relative
三:隐藏滚动条
 {overflow: hidden !important;}  或者 {overflow-x: hidden;    overflow-y: hidden;}可分别隐藏x轴或y轴的滚动条
-->
<div id="list"
     class="pre-scrollable"
     style="height:823px;overflow:auto;">
    <p>...</p>
    <p>...</p>
    <p>...</p>
    <p>...</p>
    ......
</div>
若使用pre-scrollable,则要设置样式,pre-scrollable会限制块的高度,
<style type="text/css">
    .pre-scrollable {
        max-height: 100%;  //最大高度为340px
        overflow-y: scroll;
    }
</style>

还要写js,规定其样式

$("#list").mCustomScrollbar({
        theme: "dark",//主题
        axis: "y" //X轴的话:axis:"x"  xy都要:axis:"xy"
})

在具体的可以去官网学习mCustomScrollbar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值