自用懒加载(其实效果并不是很好),自带的懒加载还好(2)(优化)
生活随笔
收集整理的這篇文章主要介紹了
自用懒加载(其实效果并不是很好),自带的懒加载还好(2)(优化)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對onPageScroll中的setData賦值次數進行節流 https://www.jianshu.com/p/b835527a792e(沒看完) onPageScroll: function (e) { console.log(e); let arrHeight = this.data.arrHeight; let imgArr = this.data.imgArr; let screenH = this.data.screenH; let n=this.data.n; let chen=0; if (!this.data.imgshownext){ return; } for (let i = 0; i < arrHeight.length; i++) { // 方案一 // 這里暫時效果不是很好,所以可以把距離改改 // if (arrHeight[i]<e.scrollTop+screenH ){ // imgArr[i]=true; // } // 方案二 // 距離稍微早一點釋放,距離底部100就釋放 // 效果依然不好 if (arrHeight[i]<e.scrollTop+screenH+100){ imgArr[i]=true; chen++; } } console.log(imgArr) if (chen>n){ console.log(chen) this.setData({ imgArr, imgshownext: false, n:chen }) }
setTimeout(()=>{ this.setData({ imgshownext: true })
},500) }, init: function (itemHeight){ let imgArr = this.data.imgArr; let arrHeight = this.data.arrHeight; let index = parseFloat(this.data.screenH/itemHeight); let n=0; // 先展示屏幕為滾動時的展示圖片,這里是兩列,所以*2 for(let i=0;i<index*2;i++){ imgArr[i]=true; n++; } // 5為高度是的間距,94為初始距離頂部的距離 for (let i = 0; i < imgArr.length; i++) { arrHeight[i] = Math.floor(i / 2) * (itemHeight+5)+94 } console.log(imgArr) console.log(arrHeight) this.setData({ imgArr, arrHeight, n}) },
setTimeout(()=>{ this.setData({ imgshownext: true })
},500) }, init: function (itemHeight){ let imgArr = this.data.imgArr; let arrHeight = this.data.arrHeight; let index = parseFloat(this.data.screenH/itemHeight); let n=0; // 先展示屏幕為滾動時的展示圖片,這里是兩列,所以*2 for(let i=0;i<index*2;i++){ imgArr[i]=true; n++; } // 5為高度是的間距,94為初始距離頂部的距離 for (let i = 0; i < imgArr.length; i++) { arrHeight[i] = Math.floor(i / 2) * (itemHeight+5)+94 } console.log(imgArr) console.log(arrHeight) this.setData({ imgArr, arrHeight, n}) },
轉載于:https://www.cnblogs.com/dianzan/p/10775810.html
總結
以上是生活随笔為你收集整理的自用懒加载(其实效果并不是很好),自带的懒加载还好(2)(优化)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VUE初长成【部分小记】
- 下一篇: awk 详解