Convert Figma logo to code with AI

wangdahoo logovue-scroller

Scroller Component for Vue.js

1,789
388
1,789
113

Top Related Projects

Adds a directive that listens for click events and scrolls to elements.

An infinite scroll directive for vue.js.

⚡️ Blazing fast scrolling for any amount of data

Quick Overview

Vue-scroller is a Vue.js component that provides smooth scrolling functionality with pull-to-refresh and infinite loading capabilities. It's designed to enhance the user experience in mobile web applications by offering native-like scrolling behavior and common mobile interaction patterns.

Pros

  • Easy integration with Vue.js projects
  • Supports both pull-to-refresh and infinite loading
  • Customizable styling and behavior
  • Lightweight and performant

Cons

  • Limited documentation and examples
  • May not be actively maintained (last commit was over 2 years ago)
  • Might have compatibility issues with newer Vue.js versions
  • Lacks advanced features found in some alternative scrolling libraries

Code Examples

  1. Basic usage:
<template>
  <scroller>
    <div v-for="item in items" :key="item.id">
      {{ item.text }}
    </div>
  </scroller>
</template>

<script>
import { Scroller } from 'vue-scroller'

export default {
  components: { Scroller },
  data() {
    return {
      items: [/* ... */]
    }
  }
}
</script>
  1. Pull-to-refresh implementation:
<template>
  <scroller :on-refresh="refresh" ref="scroller">
    <!-- Content here -->
  </scroller>
</template>

<script>
export default {
  methods: {
    refresh(done) {
      // Fetch new data
      setTimeout(() => {
        // Update data
        done() // Call when refresh is complete
      }, 1500)
    }
  }
}
</script>
  1. Infinite loading:
<template>
  <scroller :on-infinite="loadMore" ref="scroller">
    <!-- Content here -->
  </scroller>
</template>

<script>
export default {
  methods: {
    loadMore(done) {
      // Load more data
      setTimeout(() => {
        // Append new data
        done() // Call when loading is complete
      }, 1500)
    }
  }
}
</script>

Getting Started

  1. Install the package:

    npm install vue-scroller
    
  2. Import and use in your Vue component:

    <template>
      <scroller>
        <!-- Your scrollable content here -->
      </scroller>
    </template>
    
    <script>
    import { Scroller } from 'vue-scroller'
    
    export default {
      components: { Scroller }
    }
    </script>
    
  3. Configure options as needed (e.g., pull-to-refresh, infinite loading) using props and event handlers.

Competitor Comparisons

Adds a directive that listens for click events and scrolls to elements.

Pros of vue-scrollto

  • Lightweight and focused solely on scrolling functionality
  • Supports both Vue 2 and Vue 3
  • Offers more customization options for easing and duration

Cons of vue-scrollto

  • Limited to scrolling within the same page
  • Lacks pull-to-refresh and infinite scrolling features
  • May require additional plugins for more complex scrolling behaviors

Code Comparison

vue-scrollto:

import VueScrollTo from 'vue-scrollto'

Vue.use(VueScrollTo, {
  container: "body",
  duration: 500,
  easing: "ease",
  offset: 0,
  force: true,
  cancelable: true,
  onStart: false,
  onDone: false,
  onCancel: false,
  x: false,
  y: true
})

vue-scroller:

import VueScroller from 'vue-scroller'

Vue.use(VueScroller)

<scroller
  :on-refresh="refresh"
  :on-infinite="infinite">
  <!-- content -->
</scroller>

vue-scrollto is more focused on smooth scrolling to specific elements within a page, offering various configuration options. vue-scroller, on the other hand, provides a more comprehensive solution for mobile-oriented scrolling, including pull-to-refresh and infinite scrolling functionalities. The choice between the two depends on the specific scrolling requirements of your Vue.js project.

An infinite scroll directive for vue.js.

Pros of vue-infinite-scroll

  • Lightweight and focused solely on infinite scrolling functionality
  • Easy to implement with minimal configuration
  • Supports both upward and downward infinite scrolling

Cons of vue-infinite-scroll

  • Limited customization options compared to vue-scroller
  • Lacks built-in pull-to-refresh functionality
  • May require additional components for more complex scrolling scenarios

Code Comparison

vue-infinite-scroll:

<div v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" infinite-scroll-distance="10">
  <!-- Content -->
</div>

vue-scroller:

<scroller :on-infinite="infinite" ref="myscroller">
  <!-- Content -->
</scroller>

vue-infinite-scroll uses a directive approach, while vue-scroller employs a component-based implementation. vue-scroller offers more built-in features and customization options, making it suitable for complex scrolling scenarios. However, vue-infinite-scroll's simplicity and focused functionality make it an excellent choice for basic infinite scrolling needs.

Both libraries have their strengths, and the choice between them depends on the specific requirements of your project. vue-infinite-scroll is ideal for simple implementations, while vue-scroller is better suited for more advanced use cases requiring additional features and customization.

⚡️ Blazing fast scrolling for any amount of data

Pros of vue-virtual-scroller

  • Better performance for large lists due to virtual scrolling
  • More active development and maintenance
  • Supports both horizontal and vertical scrolling

Cons of vue-virtual-scroller

  • More complex implementation
  • Requires additional setup for dynamic item sizes
  • May have a steeper learning curve for beginners

Code Comparison

vue-scroller:

<scroller
  :on-refresh="refresh"
  :on-infinite="infinite">
  <!-- content -->
</scroller>

vue-virtual-scroller:

<RecycleScroller
  class="scroller"
  :items="list"
  :item-size="32"
  key-field="id"
  v-slot="{ item }">
  <!-- item template -->
</RecycleScroller>

vue-scroller is simpler to implement for basic scrolling needs, while vue-virtual-scroller offers more advanced features and better performance for large datasets. vue-virtual-scroller requires specifying item size and key field, which allows for more efficient rendering of list items. However, this also means it requires more setup and configuration compared to vue-scroller.

vue-scroller focuses on pull-to-refresh and infinite scrolling functionalities, making it easier to implement these common mobile app features. On the other hand, vue-virtual-scroller is more suited for efficiently rendering large lists with smooth scrolling performance, regardless of the number of items.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Vue Scroller version vue

Vue Scroller is a foundational component of Vonic UI. In purpose of smooth scrolling, pull to refresh and infinite loading.

For vue 1.0, please refer to branch v1.

Demo

https://wangdahoo.github.io/vue-scroller/

How to use

npm i vue-scroller -S
/* ignore this if you include vue-scroller.js by <script> tag from a cdn, such as unpkg */
import Vue from 'vue'
import VueScroller from 'vue-scroller'
Vue.use(VueScroller)
<scroller 
  :on-refresh="refresh"
  :on-infinite="infinite">
  <!-- content goes here -->
</scroller>

Live Code on JsFiddle

Webpack project by vue-cli

https://github.com/wangdahoo/vue-scroller-demo

API

Scroller component attributes:

Attr. NameDescriptionRequiredDefault Value
onRefreshpull to refresh callbackN-
onInfiniteinfinite loading callbackN-
refreshTexttips of pull-to-refreshN下拉刷新
noDataTexttips of no-more-data when infinite-loading finishedN没有更多数据
widthscroller container widthN100%
heightscroller container heightN100%
snappingenable snapping modeNfalse
snappingWidthsnapping widthN100 (stand for 100px)
snappingHeightsnapping heightN100
refreshLayerColortext color of pull-to-refresh layerN#AAA
loadingLayerColortext color of infinite-loading layerN#AAA
minContentHeightmin content height (px) of scroll-contentN0

Scroller vm instance methods:

  • resize() resize scroller content (deprecated, cause the scroller's content resizes self automatically)
  • triggerPullToRefresh() start pull-to-refresh manually
  • finishPullToRefresh() stop pull-to-refresh
  • finishInfinite(isNoMoreData :Boolean) stop infinite-loading
  • scrollTo(x:Integer, y:Integer, animate:Boolean) scroll to a position in scroller content
  • scrollBy(x:Integer, y:Integer, animate:Boolean) scroll by a position in scroller content
  • getPosition :Object get current position of scroller content

NPM DownloadsLast 30 Days