js實(shí)現(xiàn)瀑布流觸底動(dòng)態(tài)加載數(shù)據(jù)
本文實(shí)例為大家分享了js實(shí)現(xiàn)瀑布流觸底動(dòng)態(tài)加載數(shù)據(jù)的具體代碼,供大家參考,具體內(nèi)容如下

// onScrollEvent 滾動(dòng)條事件
<div class="box" ref="box" @mousewheel="onScrollEvent">
//每一個(gè)方塊內(nèi)的內(nèi)容start
<div class="boxItemStyle" v-for="(userTag, i) in dataSource" :key="i" ref="boxItemStyle">
<a-tag class="moreStyle" @click="more(userTag.primaryParam)"> 更多></a-tag>
<div v-for="item in userTag.userTag" :key="item.code">
<p>
<span style="text-align: left"> {{ item.name }}:</span>
<span style="text-align: right">{{ item.value }}</span>
</p>
</div>
</div>
//每一個(gè)方塊內(nèi)的內(nèi)容end
</div>
瀑布流布局
waterFall () {
//減去邊距的寬度
var pageWidth = this.$refs.box.offsetWidth - 200
var columns = 4; //定義一行4列
var itemWidth = parseInt(pageWidth / columns);
var arr = [];
var nodes = document.getElementsByClassName("boxItemStyle")
setTimeout(() => {
//var node1 = Array.from(nodes)
// var node2 = Array.prototype.slice.call(nodes)
for (var i = 0; i < nodes.length; i++) {
nodes[i].style.width = itemWidth + "px"
if (i < columns) {
nodes[i].style.width = itemWidth + "px"
nodes[i].style.left = itemWidth * i + i * 50 + "px"
nodes[i].style.top = 0
arr.push(nodes[i].offsetHeight);
} else {
// 找到數(shù)組中最小高度 和 它的索引
var minHeight = arr[0];
var index = 0;
for (var j = 0; j < arr.length; j++) {
if (minHeight > arr[j]) {
minHeight = arr[j];
index = j;
}
}
nodes[i].style.top = arr[index] + 30 + "px",
nodes[i].style.left = nodes[index].offsetLeft + 'px';
// 修改最小列的高度
// 最小列的高度 = 當(dāng)前自己的高度 + 拼接過(guò)來(lái)的高度
arr[index] = arr[index] + nodes[i].offsetHeight + 30;//設(shè)置30的距離
}
}
}, 1000)
},
動(dòng)態(tài)加載數(shù)據(jù)
onScrollEvent () {
if (
this.isScroll &&
this.$refs.box.scrollHeight - this.$refs.box.scrollTop -this.$refs.box.clientHeight <= 0
) {
this.loading = true
if (this.ipagination.current == 1) {
this.ipagination.current += 1
}
let param = {}
param['pageNo'] = this.ipagination.current
param['pageSize'] = this.ipagination.pageSize
param['portraitId'] = this.portraitId
postAction(this.url.list, { ...param }).then((res) => {
this.loading = false
if (res.success) {
this.isScroll = res.records
this.dataSource = this.dataSource.concat(res.result.records || res.result)
this.waterFall();
}
})
this.ipagination.current++
}
},
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript 中對(duì)象的繼承〔轉(zhuǎn)貼〕
javascript 中對(duì)象的繼承〔轉(zhuǎn)貼〕...2007-01-01
javascript firefox 自動(dòng)加載iframe 自動(dòng)調(diào)整高寬示例
iframe 自動(dòng)獲取onload高寬以及iframe 自動(dòng)加載,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下2013-08-08
JavaScript實(shí)現(xiàn)仿windows文件名稱排序
在JavaScript中,數(shù)組排序是一個(gè)常見(jiàn)的操作,本文將通過(guò)一個(gè)具體的代碼示例,解釋如何實(shí)現(xiàn)一個(gè)仿windows文件名稱的排序算法,需要的可以參考下2024-12-12
前端排查內(nèi)存泄漏的方法及實(shí)戰(zhàn)案例
內(nèi)存泄漏是指在程序運(yùn)行時(shí),分配的內(nèi)存沒(méi)有被正確釋放,導(dǎo)致內(nèi)存空間的浪費(fèi),最終可能會(huì)導(dǎo)致程序崩潰或運(yùn)行緩慢,這篇文章主要介紹了前端排查內(nèi)存泄漏的相關(guān)資料,需要的朋友可以參考下2025-03-03
postcss-pxtorem實(shí)現(xiàn)頁(yè)面自適應(yīng)的原理解析
postcss-pxtorem是一個(gè)PostCSS插件,用于將CSS中的像素值轉(zhuǎn)換為rem單位,以實(shí)現(xiàn)響應(yīng)式布局和適配不同屏幕尺寸的需求,本文給大家介紹postcss-pxtorem實(shí)現(xiàn)頁(yè)面自適應(yīng)的原理解析,感興趣的朋友一起看看吧2023-12-12
js格式化貨幣數(shù)據(jù)實(shí)現(xiàn)代碼
貨幣數(shù)據(jù)想要一某種形式在頁(yè)面中顯示的話,首先是必須要格式化的,下面為大家介紹下具體的格式化代碼,感興趣的朋友可以參考下2013-09-09
詳解WordPress開發(fā)中g(shù)et_current_screen()函數(shù)的使用
這篇文章主要介紹了WordPress開發(fā)中g(shù)et_current_screen()函數(shù)的使用,get_current_screen()通常在對(duì)象的實(shí)例化時(shí)使用,需要的朋友可以參考下2016-01-01
uniapp中uni.navigateBack返回后刷新頁(yè)面數(shù)據(jù)的實(shí)現(xiàn)
本文主要介紹了uniapp中uni.navigateBack返回后刷新頁(yè)面數(shù)據(jù)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-11-11

