GithubHelp home page GithubHelp logo

blackbp / vue-smooth-scrollbar Goto Github PK

View Code? Open in Web Editor NEW
4.0 0.0 2.0 4.04 MB

A wrapper for smooth-scrollbar to Vue Component

Home Page: https://blackbp.github.io/vue-smooth-scrollbar/

License: MIT License

JavaScript 9.99% HTML 2.61% Vue 87.40%
smooth-scrolling smooth-scrollbar vue component vuecomponent scrollbar

vue-smooth-scrollbar's Introduction

vue-smooth-scrollbar

idiotWu/smooth-scrollbar for Vue.js projects.

Features

  1. Infinite loading

Demo

GitHub Pages

Usage

1. Install dependency

yarn add @blackbp/vue-smooth-scrollbar

2. Import component into your app.js or component

In your App.js

import Vue from 'vue'
...
import ScrollView from '@blackbp/vue-smooth-scrollbar'
...

new Vue({
    components: {
        ScrollView
    }
})

In vue single file component

import ScrollView from '@blackbp/vue-smooth-scrollbar'

export default {
    components: {
        ScrollView
    }
}

3. Use component in your templates

You should set height to component! This is important

<template>
    <scroll-view class="scroll-area">
        ...awesome content
    </scroll-view>
</template>

<style>
  .scroll-area {
    width: 100%;
    height: 500px; // You should set height to component! This is important
  }
</style>

Props

Prop name Type Default Description
infiniteLoading Boolean false Enable infinite loading
loadThreshold Number 50 Infinite loading threshold (distance from a bottom of content)
options Object {} smooth-scroll options. See here.
plugins Array [] Array of smooth-scrollbar plugins

Events

Event name Args Description
@endy - Reaching the end of the scroll on the y axis
@endx - Reaching the end of the scroll on the x axis
@scroll status: Object Fires when scrolling on every axis (see details below)
@loading state: Object Fires when reaching the end of the content

@scroll status object:

let status = {
    offset: {
        x: number,
        y: number,
    },
    limit: {
        x: number,
        y: number,
    },
}

@loading state object:

// Your component
<template>
    <scroll-view ref="scrollView" 
                 :infinite-loading="true" 
                 @loading="onInfinite">
        <div v-for="item in list" 
             :key="`awesome-item-${item.id}`">
            ...awesome content
        </div>
    </scroll-view>
</template>

export default {
    data() {
        return {
            list: [],
            page: 1
        }
    },
    methods: {
        async onInfinite(state) {
            let res = await someAsyncFunc();
            
            if(res.list) {
                this.list.push(...rest.list);
                this.page = ++this.page;
                state.loaded(); // If there is data, then set state loaded (keep emit @loading event)
            } else {
                state.completed(); // If no data, then set state completed (stop emit @loading event)
            }
        },
        resetInfScroll() {
            this.$refs.scrollView.resetInfLoad(); // Resets the state of the infinite load
        }
    }
}

To run example

Clone this repo

yarn install
yarn run serve

Backlog

  • Plugin structure
  • Basic implementation
  • Options
  • Events
  • Methods
  • Styling
  • Build dist
  • SSR / nuxt

vue-smooth-scrollbar's People

Contributors

blackbp avatar

Stargazers

 avatar  avatar  avatar  avatar

vue-smooth-scrollbar's Issues

Is this project still alive?

I've found this project incredibly useful, however the dependencies are out of date leading to breakages with newer versions of the base smooth-scrollbar project. I've managed to get some kind of upgrade done, although since this was for a time-dependent project (and honestly I'm still kind of new to this stuff) it isn't in the best shape and neglects the linting and formatting.

Is this package still maintained or is it acceptable for me to push my fork to NPM to keep it alive?

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.