Git Product home page Git Product logo

vue-virtual-scroll-list's Introduction

NPM version Vue version MIT License

vue-virtual-scroll-list

A vue (2.x) component support big data and infinite loading by using virtual scroll list.

  • Tiny and easy to use.

  • Big data list and infinite loading.

  • Set the initial scroll index or change any.

  • List scrolling, to top and bottom can be detected.

How it works

Demos

Usage

Using by npm:

npm install vue-virtual-scroll-list --save
<template>
    <div>
        <virtualList :size="40" :remain="8">
            <Item v-for="(item, index) of items" :item="item" :key="item.id" />
        </virtualList>
    </div>
</template>

<script>
    import Item from '../item.vue'
    import virtualList from 'vue-virtual-scroll-list'

    export default {
        name: 'demo',
        data () {
            return {
                items: [...]
            }
        },
        components: { Item, virtualList }
    }
</script>

The <Item> component is included inside but defined outside the <virtualList> component. We see that <virtualList> not rely on <Item> component. So you can use virtual-list with any list item component freely.

Using by script tag:

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://tangbc.github.io/vue-virtual-scroll-list/index.js"></script>

<div id="app">
    <virtual-list :size="40" :remain="8">
        <div class="item" v-for="(item, index) of items" :key="index">Item: # {{ index }}</div>
    </virtual-list>
</div>
// Global name as `VirutalScrollList`
Vue.component('virtual-list', VirutalScrollList)

new Vue({
    el: '#app',
    data: {
        items: new Array(100000)
    }
})

Notice: list Item component or DOM frag using v-for must designate the :key property.

Props

Prop Type Required Description
size Number Each list item height, currently only supports fixed height.
remain Number How many items except show in virtual-list viewport, so size and remian will determine the virtual-list outside container height (size × remian).
start Number * Default value is 0, the initial scroll start index. It must be integer and in the range of list index, do nothing but throw a warnning if not match.
rtag String * Default value is div, the virtual-list's root HTMLElement tag name, in all case it's style is set to display: block;
wtag String * Default value is div, the virtual-list's item wrapper HTMLElement tag name, in all case it's style is set to display: block;
onscroll Function * Call on virtual-list scroll event hanlding, param: (e, scrollTop).
totop Function * A function triggered when the virtual-list is scrolled to top.
tobottom Function * A function triggered when the virtual-list is scrolled to bottom.

Contributions

Welcome to improve vue-virtual-scroll-list by any pull request or issue.

License

MIT License

vue-virtual-scroll-list's People

Contributors

tangbc avatar youngsx avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.