vue實(shí)現(xiàn)滾動(dòng)條始終懸浮在頁(yè)面最下方
本文實(shí)例為大家分享了vue實(shí)現(xiàn)滾動(dòng)條始終懸浮在頁(yè)面最下方的具體代碼,供大家參考,具體內(nèi)容如下
需求
表格寬高都超出瀏覽器顯示大小,橫向滾動(dòng)條需要始終浮在最下方便于滾動(dòng)展示數(shù)據(jù)

思路
在表格下方添加一個(gè)滾動(dòng)條容器,并且采用position: fixed定位始終浮在頁(yè)面下方。
在通過(guò)滾動(dòng)事件綁定該容器與表格的橫向滾動(dòng)同步。
在表格內(nèi)容小于瀏覽器顯示高度時(shí),只展示表格滾動(dòng)條。

實(shí)現(xiàn)
<div class="tab-table" id="tabTable" @scroll="sysHandleScroll()" @mouseover="changeFlag(false)">
?? ?<div>table</div>
? ? <!-- ? ? ?滾動(dòng)條-->
?? ?<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;
? ? ? },
? ? ? // 左右滾動(dòng)條滾動(dòng)同步
? ? ? 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;
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue如何在vue.config.js文件中導(dǎo)入模塊
這篇文章主要介紹了vue如何在vue.config.js文件中導(dǎo)入模塊問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
多個(gè)vue項(xiàng)目實(shí)現(xiàn)共用一個(gè)node-modules文件夾
這篇文章主要介紹了多個(gè)vue項(xiàng)目實(shí)現(xiàn)共用一個(gè)node-modules文件夾,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
vue中ref標(biāo)簽屬性和$ref的關(guān)系解讀
這篇文章主要介紹了vue中ref標(biāo)簽屬性和$ref的關(guān)系,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07
unplugin-auto-import與unplugin-vue-components安裝問(wèn)題解析
這篇文章主要為大家介紹了unplugin-auto-import與unplugin-vue-components問(wèn)題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
一步一步實(shí)現(xiàn)Vue的響應(yīng)式(對(duì)象觀測(cè))
這篇文章主要介紹了一步一步實(shí)現(xiàn)Vue的響應(yīng)式(對(duì)象觀測(cè)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
關(guān)于element-ui?單選框默認(rèn)值不選中的解決
這篇文章主要介紹了關(guān)于element-ui?單選框默認(rèn)值不選中的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
element中async-validator異步請(qǐng)求驗(yàn)證使用
本文主要介紹了element中async-validator異步請(qǐng)求驗(yàn)證使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05

