1. 程式人生 > 實用技巧 >監聽dom是否滾動到底部

監聽dom是否滾動到底部

HTML:
<div class="data-box" ref="companyBox"> <el-row id="companyData" v-loading="companyLoading" element-loading-background="rgba(0, 0, 0, 0.5)" element-loading-spinner="el-icon-loading" element-loading-text="載入中..." style
="min-height: 64px" > <div v-if="empty" class="empty">暫無資料</div> <div class="company" :class="{active: item.active}" v-for="(item, index) in companyList" :key="item.jgztId" @click="showDetail(item, 'company')"> <span class
="point"></span>{{index}}-{{item.compName}} </div> </el-row> </div> js: const dataDom = document.getElementById('companyData'); this.box = this.$refs.companyBox; // 監聽這個dom的scroll事件 this.box.onscroll = () => {
//捲上去的高度+容器高度=滾動區域高度時 到底部 if (this.box.scrollTop + this.box.clientHeight === dataDom.clientHeight) { this.companyParams = { ...this.companyParams, page: ++this.companyParams.page }; this.updateCompanyList() } } css .data-box { overflow-y: scroll; height: calc(100vh - 300px); }

實現web端,滾動到底部下拉載入重新整理的功能