uniapp向上滚动虚拟列表加载更多无缝丝滑滚动如何实现?
网友回复
通过scroll监听和虚拟列表技术实现,完整代码如下:
<template> <view class="virtual-list"> <scroll-view class="scroll-view" scroll-y :scroll-top="scrollTop" :style="{ height: height + 'px' }" @scroll="onScroll" :scroll-with-animation="false" > <view class="loading" v-if="isLoading">加载中...</view> <view class="list-content" :style="{ height: totalHeight + 'px' }"> <view v-for="item in visibleData" :key="item.id" class="list-item" :style="{ transform: `translateY(${item.top}px)`, position: 'absolute', width: '100%' }" > <view :class="['message', item.isSelf ? 'self' : 'other']"> <view class="avatar">{{item.isSelf ? '我' : '对方'}}</view> <view class="content">{{item.content}}</view> </view> </view> </view> </scroll-view> </view> </template> <script> export default { data() { return { height: 0, itemHeight: 80, visibleCount: 0, bufferCount: 5, listData: [], visibleData: [], isLoading: false, scrollTop: 0, startIndex: 0, loadMoreThreshold: 500, lastLoadTime: 0, loadCooldown: 1000, totalHeight: 0, lastScrollTop: 0, scrollTimeout: null } }, async mounted() { const sysInfo = uni.getSystemInfoSync() this.height = sysInfo.windowHeight this.visibleCount = Math.ceil(this.height / this.itemHeight) + this.bufferCount * 2 await this.initData() }, methods: { async initData() { const initList = Array(30).fill(0).map((_, index) => ({ id: index, content: `Message ${index}`, isSelf: Math.random() > 0.5, top: index * this.itemHeight })) this.listData = initList this.totalHeight = this.listData.length * this.itemHeight this.updateVisibleData() }, updateVisibleData() { ...
点击查看剩余70%
有没有哪个ai人工智能动态生成鲜活带表情肢体动作逼真数字人与人类交流视频聊天?
threejs如何将iframe与video作为立方体模型一面的材质可点击交互?
UEFI与Legacy启动有啥不同?
可在u盘启动的开源匿名操作系统有哪些?
Pyloid与Pywebview打包生成桌面应用区别?
win10的iso镜像如何通过u盘来安装?
如何解决输入sora2邀请码报错:Sora is not available in The Netherlands yet
在哪可免费白嫖使用sora2生成视频?
php如何结合openai兼容的embedding向量化api实现语义化模糊关键词搜索匹配?
python如何结合qwen embedding向量化api实现语义化模糊关键词搜索匹配?