您好,登錄后才能下訂單哦!
本篇內容主要講解“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。