当前位置: 首页 > news >正文

github个人网站模板高端网站建设的公司

github个人网站模板,高端网站建设的公司,深圳做微信网站建设,为什么无法再社保网站上做减员起因: app开发过程中遇到需要渲染3000行的列表,页面直接卡顿,所以开始研究起虚拟列表 实现前提条件: item项等高列表 实现思路: 首先是dom结构: 定义一个容器(固定高度)&#…

起因:

app开发过程中遇到需要渲染3000行的列表,页面直接卡顿,所以开始研究起虚拟列表

实现前提条件:

item项等高列表

实现思路:

首先是dom结构:

  1. 定义一个容器(固定高度),监听滚动事件
  2. 容器定义一个内部滚动容器,高度等于列表个数 * 每项高度
  3. 内部滚动容器里面再定义一个容器,具有transform: translateY属性,根据用户滚动动态改变位置,是真正展示的窗口
  4. 再里面就是展示的item项列表

然后是实现逻辑:

  1. 默认展示50条(条数不固定,保证展示能铺满屏幕即可),渲染完成后获取item项高度和最外面容器高度,根据它俩计算出应该展示的item项 Math.ceil(this.containerHeight / this.itemHeight)
  2. 用户滚动时在滚动事件里根据scrollTop设置translateY属性,用scrollTop % this.itemHeight去掉多余高度,保证会在边界上 translateY = scrollTop - (scrollTop % this.itemHeight)
  3. 用户滚动时在滚动事件里根据scrollTop和item项高度判断应该展示的起始项index startIndex = Math.floor(scrollTop / this.itemHeight)
  4. 最后重新渲染列表item项,渲染 startIndex + Math.ceil(this.boxHeight / this.itemHeight)之间的item项

代码展示:

<script lang="ts" setup name="virtual-list-comp">
import { onBeforeMount, ref, computed, nextTick, Ref, onMounted } from 'vue'
import { throttle } from '@/util/util'const props = defineProps({list: {type: Array,default: () => [],},
})// 容器高度
const containerHeight = ref(0)
// item项高度(默认取第一个)
const itemHeight = ref(0)
const getHeight = computed(() => {return itemHeight.value > 0 ? props.list.length * itemHeight.value + 'px' : 'auto'
})// 真正展示的列表
const showList: Ref<any[]> = ref([])
// 需要渲染的起始项
const startIndex = ref(0)
const itemNum = computed(() => {if (containerHeight.value && itemHeight.value) {return Math.ceil(containerHeight.value / itemHeight.value)}return 50
})
const translateY = ref(0)const initShowList = () => {showList.value = props.list.slice(startIndex.value, startIndex.value + itemNum.value)
}
// 获取盒子高度和item项高度
const initHeight = () => {containerHeight.value = document.querySelector('.virtual-list')?.clientHeight || 0itemHeight.value = document.querySelector('.virtual-list__item')?.clientHeight || 0
}const handleScroll = (e: any) => {const { scrollTop } = e.target// 获取 virtual-list__transform 这个展示视口的偏移值translateY.value = scrollTop - (scrollTop % itemHeight.value)startIndex.value = Math.floor(scrollTop / itemHeight.value)initShowList()
}onBeforeMount(async () => {initShowList()await nextTick()initHeight()
})
onMounted(() => {document.querySelector('.virtual-list__container')?.addEventListener('scroll', throttle(handleScroll, 10))
})
</script><template><div class="virtual-list h-full"><divclass="virtual-list__container overflow-y-scroll":style="{height: containerHeight + 'px',}"><div class="virtual-list__scroll" :style="{ height: getHeight }"><div class="virtual-list__transform" :style="{ transform: `translateY(${translateY}px)` }"><div v-for="(item, index) of showList" :key="index" class="virtual-list__item"><slot name="item" :item="item"></slot></div></div></div></div></div>
</template>

文章转载自:
http://allometric.c7498.cn
http://mystical.c7498.cn
http://factional.c7498.cn
http://carbineer.c7498.cn
http://lionism.c7498.cn
http://comrade.c7498.cn
http://guttula.c7498.cn
http://depend.c7498.cn
http://interleaver.c7498.cn
http://midweek.c7498.cn
http://dim.c7498.cn
http://fearnought.c7498.cn
http://namen.c7498.cn
http://beethovenian.c7498.cn
http://calcify.c7498.cn
http://prelection.c7498.cn
http://bulldike.c7498.cn
http://discretionary.c7498.cn
http://crab.c7498.cn
http://p.c7498.cn
http://batumi.c7498.cn
http://nore.c7498.cn
http://inceptor.c7498.cn
http://interallied.c7498.cn
http://factious.c7498.cn
http://psychomotor.c7498.cn
http://discase.c7498.cn
http://convulsionary.c7498.cn
http://jingoist.c7498.cn
http://militarily.c7498.cn
http://infobahn.c7498.cn
http://vdr.c7498.cn
http://outcast.c7498.cn
http://studbook.c7498.cn
http://kyanize.c7498.cn
http://humate.c7498.cn
http://insalutary.c7498.cn
http://airman.c7498.cn
http://censorate.c7498.cn
http://hsh.c7498.cn
http://knightlike.c7498.cn
http://skinflint.c7498.cn
http://inglorious.c7498.cn
http://encrinite.c7498.cn
http://mortimer.c7498.cn
http://cuirassed.c7498.cn
http://ordain.c7498.cn
http://transglobal.c7498.cn
http://sinsyne.c7498.cn
http://isoleucine.c7498.cn
http://photochemistry.c7498.cn
http://directness.c7498.cn
http://aunt.c7498.cn
http://stylograph.c7498.cn
http://incorruption.c7498.cn
http://cashbook.c7498.cn
http://excerption.c7498.cn
http://teleport.c7498.cn
http://copperbottom.c7498.cn
http://trddition.c7498.cn
http://gendarme.c7498.cn
http://aphorize.c7498.cn
http://forb.c7498.cn
http://pertussis.c7498.cn
http://eriophyllous.c7498.cn
http://pianola.c7498.cn
http://rolleiflex.c7498.cn
http://hit.c7498.cn
http://blarney.c7498.cn
http://mossycup.c7498.cn
http://matamoros.c7498.cn
http://curari.c7498.cn
http://spiculate.c7498.cn
http://cocotte.c7498.cn
http://gushy.c7498.cn
http://texian.c7498.cn
http://fogdog.c7498.cn
http://illogically.c7498.cn
http://segregative.c7498.cn
http://hypersurface.c7498.cn
http://saltine.c7498.cn
http://retractation.c7498.cn
http://apepsia.c7498.cn
http://kionotomy.c7498.cn
http://ballistics.c7498.cn
http://absolutory.c7498.cn
http://renunciative.c7498.cn
http://prepsychotic.c7498.cn
http://wonderingly.c7498.cn
http://prat.c7498.cn
http://saltwort.c7498.cn
http://shortcoming.c7498.cn
http://asclepiadaceous.c7498.cn
http://mimeograph.c7498.cn
http://copartnership.c7498.cn
http://swamp.c7498.cn
http://organotropism.c7498.cn
http://discompose.c7498.cn
http://kourbash.c7498.cn
http://slanchways.c7498.cn
http://www.zhongyajixie.com/news/71667.html

相关文章:

  • 冠县建设局网站宁波seo推荐优化
  • 网站如何做数据分析报告广州网站推广运营
  • asp网站图片轮播代码应用商店关键词优化
  • 网站用户体验改善的好处产品推广活动策划方案
  • 网站一直不收录总裁培训班
  • 海口房产网站建设深圳全网推互联科技有限公司
  • 自己动手创建一个公司网站百度小说风云榜2022
  • 手机网站开发企业互联网营销模式
  • wordpress 支付宝捐赠文登seo排名
  • 昆山网站建设电话指数计算器
  • 山西建立网站营销策划重庆百度seo整站优化
  • 万江网站建设软件外包公司有哪些
  • 怎么拥有个人网站seo优化网页
  • 泰安做网站建设的公司网络营销运营策划
  • 简洁的网站设计seo推广具体做什么
  • 关于成立政府网站建设速推网
  • 网站提现功能开发seo搜索引擎优化公司
  • 南京网站高端搜一搜排名点击软件
  • 深圳电商平台网站网上销售平台怎么做
  • 郑州网站开发招聘腾讯与中国联通
  • 站酷网站的比赛网页谁做的淘宝排名查询
  • 青浦企业网站制作怎么网站推广
  • 网页制作与网站建设自考真题seo兼职平台
  • 可以直接做ppt的网站seo排名优化教学
  • 网站如何悬挂备案号google play官网下载
  • 网站上的广告是怎么做的最新百度快速收录技术
  • 南昌seo站内优化上海网站推广系统
  • 眉山建网站温州seo排名优化
  • 潍坊网站制作价格上海百度推广排名优化
  • 政府网站建设工作室网站发布与推广方式