All Projects → cristovao-trevisan → vue-auto-virtual-scroll-list

cristovao-trevisan / vue-auto-virtual-scroll-list

Licence: MIT license
A vue (2.x) component for large lists with variable item height

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vue-auto-virtual-scroll-list

Fairygui Unity
A flexible UI framework for Unity
Stars: ✭ 2,007 (+6590%)
Mutual labels:  virtual-list
Vue Virtual Scroll List
⚡️A vue component support big amount data list with high render performance and efficient.
Stars: ✭ 3,201 (+10570%)
Mutual labels:  virtual-list
virtual-block
🌈vue-virtual-block render what's visible
Stars: ✭ 45 (+50%)
Mutual labels:  virtual-list
react-virtual-list
A tiny virtualization list component(gzipped 6KB), supports dynamic height: https://dwqs.github.io/react-virtual-list/
Stars: ✭ 45 (+50%)
Mutual labels:  virtual-list

vue-auto-virtual-scroll-list

High level component for virtual list where each item height is not known before render

npm version package-size

Live Demo

Properties

Prop Type Required/Default Description
totalHeight Number Container height (px): used to calculate the # of components rendered
defaultHeight Number Item expected height (px). Set to your item's minimum height
extraItems Number 1 Extra items rendered (extra items rendered to avoid empty space while scrolling)

Usage

With template

<template>
  <VueAutoVirtualScrollList
    :totalHeight="800"
    :defaultHeight="80"
    style="width: 100%;"
  >
    <div
      v-for="item in items"
        :style="{ height: `${item.height}px` }"
    >
      {{ item.name }}
    </div>
  </VueAutoVirtualScrollList>
</template>

<script>
import VueAutoVirtualScrollList from 'vue-auto-virtual-scroll-list'

export default {
  ...
  components: { VueAutoVirtualScrollList },
  ...
}
</script>

With jsx

import VueAutoVirtualScrollList from 'vue-auto-virtual-scroll-list'

export default {
  ...
  render(h) {
    return (
      <VueAutoVirtualScrollList
        totalHeight={800}
        defaultHeight={80}
      >
        {items.map((item) => (
          <div style={{ height: `${item.height}px` }}>
            { item.name }
          </div>
        ))}
      </VueAutoVirtualScrollList>
    )
  },
  ...
}

Methods

setIndex(index: number)

Scroll to the item at index. This method is not yet stable or tested.

How it works

The number of rendered components is calculated by accumulating each item height to see how many fit in totalHeight. Each item height is assumed to be defaultHeight, until it is actually rendered. When that happens the correct value is cached and used for later calculations

Motivation

The worst case scenario for lists is when each item has multi-line text mixed with other content, which make it very hard to know the component height before render happens. This component makes it easy to use this kind of list without further problems

TODO

  • Support for infinite scroll
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].