Giter VIP home page Giter VIP logo

smooth-vuebar's Introduction

smooth-vuebar

Vue directive wrapper for smooth-scrollbar

Demo

You can refer to the wrapped library's demo.

Why

There are many other wrappers for this library but none of them implements the original library as directive.

I think directives are the right way to handle this kind of DOM manipulation, so let it be.

Also, there are so many problems I found while trying SSR that the only available choice for me was doing it by myself.

Install

npm i smooth-vuebar

Vue.use(SmoothVuebar)

SSR (nuxt): install as client plugin

Safari and IE: this library requires a CustomEvent polyfill.

Usage

Usually this plugin is used app-wide.

Vue

<template>
  <div>
    <div v-smoothscrollbar="{ listener, options }">
      <router-view />
    </div>
  </div>
</template>

Nuxt & Gridsome

this is a default.vue layout:

<template>
  <div>
    <div
      v-smoothscrollbar="{ listener, options }"
      @insert=".."
      @unbind="..">
      <nuxt />
    </div>
  </div>
</template>

However, you can use it where you want, just mind the default css:

.smooth-vuebar {
  max-width: 100vw;
  max-height: 100vh;
}

And replace it as you wish.

Options

The directive can be customized passing an object.

<div v-smoothscrollbar="{ listener, options }">
  • listener (default: undefined) => can be a function, it will automatically set as listener.

  • options (default: undefined) => can be an object.

Please refer to the offical API docs.

Events

The directive implements two extra events, useful when you want to retrieve the Scrollbar istance and use it.

  • @insert - fired when the DOM element is inserted and the library is loaded on it. The callback may be a function (e).

  • @unbind - fired when the DOM element is unbound and the library is unloaded. The callback may be a function (e).

Extra

You can define global default options. They are valid only if you don't set any local option.

Try it:

Vue.use(SmoothVuebar, {
  listener: () => {},
  options: {}
})

Play with the core

If you want to use the actual wrapper library, here is an helper, available in every component:

this.$scrollbar

Or project-wide

import Vue from 'vue'

Vue.scrollbar

Refer to offical API docs.

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.