Code Monkey home page Code Monkey logo

vue-scrolly's Introduction

vue-scrolly npm tag

Overlay scrollbar for Vue.js.


Check out the live demo.

Features

  • Supports vertical & horizontal scrollbars.
  • Easy scrollbar configration - everything using CSS!
  • Uses MutationObserver to update scrollbar size & position.
  • Supports min-height (default 20% of viewport) to ensure scrollbar remains draggable on very long content.
  • When user has scrolled to the beginning or the end of content, Scrolly seamlessly activates scrolling of parent body by detecting if user scrolled with greater scroll inertia.

Installation

$ npm install vue-scrolly

Using vue-scrolly

First, import vue-scrolly into your Vue component.

import { Scrolly, ScrollyViewport, ScrollyBar } from 'vue-scrolly';

export default {
  // ...
  components: {
    Scrolly,
    ScrollyViewport,
    ScrollyBar
  }
}

Then, construct your div block with overlay scrollbar using scrolly component.

<scrolly class="foo" :style="{ width: '400px', height: '300px' }">
  <scrolly-viewport>
    <!-- Your contents here -->
  </scrolly-viewport>
  <scrolly-bar axis="y"></scrolly-bar>
  <scrolly-bar axis="x"></scrolly-bar>
</scrolly>

Customizing overlay scrollbar

You can customize the appearance of the overlay scrollbar using CSS overrides.

This simple example below creates custom blue overlay scrollbar:

.scrolly.foo .scrolly-bar:before {
    background: blue;
}

For complete reference, you can look at vue-scrolly's default CSS stylesheet from the main Scrolly.vue component file.

Options

Scrolly

Property Description Type Default
parentScroll Scroll parent when user has completed scrolling to the beginning or the end of the viewport. Boolean true
passiveScroll When true, mousewheel event is attached as a non-blocking passive listener for improved scrolling performance. Disabling parentScroll will not be possible. See: https://www.chromestatus.com/feature/5745543795965952 Boolean false

ScrollyBar

Property Description Type Default
axis Displays horizontal or vertical scrollbar. String [x, y] y

Events

Event Description Parameters
scrollchange Triggers when user scrolls the viewport scrollLayout: object

License

vue-scrolly by Yan Sern licensed under the MIT+BSD. This project also uses normalizeWheel packaged by basilfx which contains codes extracted from BSD-licensed Fixed Data Table project by Facebook.

PS: I would love to know if you're using vue-scrolly. Tweet to me at @yansernio.

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.