本篇内容主要讲解“element-ui滚动条el-scrollbar置底的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“element-ui滚动条el-scrollbar置底的方法”吧!
在需要滚动的地方加上
<el-scrollbar ref="myScrollbar" ></el-scrollbar>
方法
scrollDown() { this.$refs['myScrollbar'].wrap.scrollTop = this.$refs['myScrollbar'].wrap.scrollHeight }
不能在接收数据时调用,需要在页面渲染结束时调用方法
updated: function() { this.scrollDown() }
实现效果:
1、template部分代码
<template> <!-- 外面的最大的父容器盒子 --> <div class="ccc"> <!-- 使用el-scrollbar标签的效果 --> <div class="box"> <!-- 隐藏标签scrollbar包住所有滚动内容 --> <el-scrollbar> <el-table :data="tableData" > <el-table-column prop="date" label="日期" width="180"> </el-table-column> <el-table-column prop="name" label="姓名" width="180"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> </el-table> </el-scrollbar> </div> <!-- 没有使用el-scrollbar标签普通容器效果 --> <div class="box2"> <el-table :data="tableData" > <el-table-column prop="date" label="日期" width="180"> </el-table-column> <el-table-column prop="name" label="姓名" width="180"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> <el-table-column prop="address" label="地址" width="480"> </el-table-column> </el-table> </div> </div> </template>
2、script数据部分的代码
<script> export default { // 数据 data () { return { tableData: [ { date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' }, { date: '2016-05-04', name: '王小虎', address: '上海市普陀区金沙江路 1517 弄' }, { date: '2016-05-01', name: '王小虎', address: '上海市普陀区金沙江路 1519 弄' }, { date: '2016-05-03', name: '王小虎', address: '上海市普陀区金沙江路 1516 弄' } ] } } } </script>
3、css样式部分代码
<style> .ccc .box { width: 100%; height: 400px; border: 1px solid red; margin: 0 auto; white-space: nowrap; } .ccc .el-scrollbar { height: 100%; } .ccc .box2 { margin-top: 50px; height: 200px; overflow: overlay; } /* 最为关键得两个样式代码,可以设置全局滚动条样式,也可以按需设置 */ .ccc ::-webkit-scrollbar { /* 设置竖向滚动条的宽度 */ width: 5px; /* 设置横向滚动条的高度 */ height: 5px; } .ccc ::-webkit-scrollbar-thumb { /*滚动条的背景色*/ background-color: rgba(144,147,153,.3); border-radius: 35px; position: relative; } </style>
到此,相信大家对“element-ui滚动条el-scrollbar置底的方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。