vue實現(xiàn)滾動條始終懸浮在頁面最下方
本文實例為大家分享了vue實現(xiàn)滾動條始終懸浮在頁面最下方的具體代碼,供大家參考,具體內(nèi)容如下
需求
表格寬高都超出瀏覽器顯示大小,橫向滾動條需要始終浮在最下方便于滾動展示數(shù)據(jù)
思路
在表格下方添加一個滾動條容器,并且采用position: fixed定位始終浮在頁面下方。
在通過滾動事件綁定該容器與表格的橫向滾動同步。
在表格內(nèi)容小于瀏覽器顯示高度時,只展示表格滾動條。
實現(xiàn)
<div class="tab-table" id="tabTable" @scroll="sysHandleScroll()" @mouseover="changeFlag(false)"> ?? ?<div>table</div> ? ? <!-- ? ? ?滾動條--> ?? ?<div ? ? ? v-show="tableHeight >= clientHeight" ? ? ? class="table-scrool" ? ? ? id="externalForm" ? ? ? @scroll="handleScroll()" ? ? ? @mouseover="changeFlag(true)" ? ? ? :style="{ width: `${screenWidth + 'px'}` }" ? ? > ? ? ?? ?<div :style="{ width: `${listWidth + 'px'}` }" style="height: 5px"></div> ? ? </div> </div>
<script> ? export default { ? ? data() { ? ? ? return { ? ? ? ? screenWidth: 0, ? ? ? ? listWidth: 0, ? ? ? ? flag: false, ? ? ? ? clientHeight: 0, ? ? ? ? tableHeight: 0, ? ? ? }; ? ? }, ? ? mounted() { ? ? ? this.setSize(); ? ? ? window.addEventListener('resize', this.setSize, false); ? ? ? this.$nextTick(() => { ? ? ? ? this.clientHeight = document.documentElement.clientHeight; ? ? ? ? this.tableHeight = document.getElementById('tabTable').clientHeight; ? ? ? }); ? ? }, ? ? beforeUnmount() { ? ? ? window.removeEventListener('resize', this.setSize, false); ? ? }, ? ? methods: { ? ? ? setSize: function () { ? ? ? ? this.screenWidth = document.getElementById('tabTable').offsetWidth; ? ? ? ? this.listWidth = 0; ? ? ? ? this.listHeader.list.forEach((item) => { ? ? ? ? ? ? this.listWidth = this.listWidth + item.length * 10; ? ? ? ? }); ? ? ? ? if (this.listWidth < this.screenWidth) { ? ? ? ? ? this.listWidth = this.screenWidth; ? ? ? ? } ? ? ? }, ? ? ? changeFlag(flag) { ? ? ? ? this.flag = flag; ? ? ? }, ? ? ? // 左右滾動條滾動同步 ? ? ? sysHandleScroll() { ? ? ? ? if (!this.flag) { ? ? ? ? ? document.getElementById('externalForm').scrollLeft = ? ? ? ? ? ? document.getElementById('tabTable').scrollLeft; ? ? ? ? } ? ? ? }, ? ? ? handleScroll() { ? ? ? ? document.getElementById('tabTable').scrollLeft = ? ? ? ? ? document.getElementById('externalForm').scrollLeft; ? ? ? }, ? ? }, ? }; </script>
CSS
.tab-table { ?? ? margin: 0 16px 15px 16px; ?? ? overflow-x: auto; ?? ? white-space: nowrap; } .table-scrool{ ?? ?height: 5px; ?? ?position: fixed; ?? ?bottom: 0; ?? ?overflow-x: auto; ?? ?overflow-y: hidden; ?? ?z-index: 12; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Electron主進程(Main?Process)與渲染進程(Renderer?Process)通信詳解
這篇文章主要介紹了Electron主進程(Main?Process)與渲染進程(Renderer?Process)通信,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03vue使用axios時關(guān)于this的指向問題詳解
最近在學(xué)習(xí)使用vue+axios,在使用中發(fā)現(xiàn)了一個問題,下面總結(jié)分享給大家,這篇文章主要給大家介紹了關(guān)于vue使用axios時this的指向問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下。2017-12-12詳解vue數(shù)據(jù)響應(yīng)式原理之?dāng)?shù)組
這篇文章主要為大家詳細介紹了vue數(shù)據(jù)響應(yīng)式原理之?dāng)?shù)組,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-02-02Vuejs第一篇之入門教程詳解(單向綁定、雙向綁定、列表渲染、響應(yīng)函數(shù))
組件(Component)是 Vue.js 最強大的功能之一。接下來給大家介紹vuejs單向綁定、雙向綁定、列表渲染、響應(yīng)函數(shù)的相關(guān)知識,非常不錯,感興趣的朋友一起看看吧2016-09-09關(guān)于vue v-for 循環(huán)問題(一行顯示四個,每一行的最右邊那個計算屬性)
這篇文章主要介紹了關(guān)于vue v-for 循環(huán)問題(一行顯示四個,每一行的最右邊那個計算屬性),需要的朋友可以參考下2018-09-09Vue自定義指令實現(xiàn)checkbox全選功能的方法
下面小編就為大家分享一篇Vue自定義指令實現(xiàn)checkbox全選功能的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02