GithubHelp home page GithubHelp logo

bosnaufal / vue2-scrollbar Goto Github PK

View Code? Open in Web Editor NEW
235.0 8.0 80.0 960 KB

The Simplest Pretty Scroll Area Component with custom scrollbar for Vue 2. https://bosnaufal.github.io/vue2-scrollbar

License: MIT License

HTML 14.55% Vue 73.79% JavaScript 11.66%
vue scrollbar custom-scrollbar vue-scrollbar vuejs2 vue2

vue2-scrollbar's Introduction

Vue 2 Scrollbar

The Simplest Scroll Area Component with custom scrollbar for Vue 2. It's based on react-scrollbar. All animation, Height and Width are pure CSS, So it's TOTALLY CUSTOMIZABLE and RESPONSIVE! YEAH!.

DEMO

Install

You can import vue-scrollbar.vue to your vue component file like this and process it with your preprocessor.

You can install it via NPM

npm install vue2-scrollbar

Or Just put it after Vue JS~

<script src="https://vuejs.org/js/vue.min.js"></script>
<script src="./dist/vue2-scrollbar.js"></script>
<script>
  // Don't Forget to register it
  new Vue({
    components: {
      scrollbar: Vue2Scrollbar
    }
  });
</script>

Import Style

Don't forget to import vue 2 css. You can link it via html

<link rel="stylesheet" href="vue2-scrollbar/dist/style/vue2-scrollbar.css">

Or You can import it using commonJS

require('vue2-scrollbar/style/vue2-scrollbar.css')

Its style is very customizable. You can put any CSS over it. And You can add custom class via its prop.

Import Module

import ScrollBar from 'vue2-scrollbar'
// Or
var ScrollBar = require('vue2-scrollbar');

Usage

<template>
  <div>
    <vue-scrollbar classes="my-scrollbar" ref="Scrollbar">
      <div class="scroll-me">
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="clearfix"></div>
      </div>
    </vue-scrollbar>
  </div>
</template>

<script>

  import VueScrollbar from 'vue2-scrollbar';
  require("vue2-scrollbar/style/vue2-scrollbar.css")

  // It's required to set min height of the scrollbar wrapper
  require("./your/custom/style/app.css")

  export default {
    components: { VueScrollbar },
  };

</script>

Props

clasess (String)

Just the ordinary class name for styling the wrapper. So, It's TOTALLY CUSTOMIZABLE!

/*The Wrapper*/
.my-scrollbar{
  width: 35%;
  min-width: 300px;
  max-height: 450px;
}

/*The Content*/
.scroll-me{
  min-width: 750px;
}
style (Object)

If you prefer to use inline style to styling the scrollbar, you can pass the styling object to this props.

this.styling = {

  /* Scrollbar */
  scrollbar: {
    width: "35%",
    minWidth: "300px",
    maxHeight: "450px"
  },

}
<vue-scrollbar :style="styling.scrollbar"></vue-scrollbar>
speed (Number)

The wheel step in pixel. The default is 53 pixel per wheel.

onMaxScroll (type: Function, return: Object)

Applied when the scrollbar in the max vertical or max horizontal scrolling. Make a possibility to add some load more feature or infinite scroll

// Examples
handleMaxScroll(direction) {
  console.log(direction);
}
<vue-scrollbar :onMaxScroll="handleMaxScroll"></vue-scrollbar>

Methods

You can do some methods by accessing the component via javascript.

this.$refs.scrollbar.someMethod()
scrollToY(y)

To scroll the scrollbar to the Y

// Examples
someMethod() {
  this.$refs.Scrollbar.scrollToY(100)
}
scrollToX(x)

To scroll the scrollbar to the X

// Examples
someMethod() {
  this.$refs.Scrollbar.scrollToX(100)
}

Thank You for Making this useful~

Let's talk about some projects with me

Just Contact Me At:

License

MIT Copyright (c) 2016 - forever Naufal Rabbani

vue2-scrollbar's People

Contributors

bosnaufal avatar maryleloisa avatar simondavies avatar trakout avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue2-scrollbar's Issues

Exception when not available on mount

(Using Vue 2.5.16, Chrome 65)

When using the component on an hidden parent which first shows up under certain conditions (i.e. within a <div v-show="shown">...</div>), i get an exception Error in mounted hook: "TypeError: Cannot read property 'clientHeight' of undefined" in vue-scrollbar.vue line 267.

This is probably due to the non-rendered children which are just assumed that they exist. It's possible to work around it using the v-if-directive but I often came across cases where that is not feasable.

Unfortunately this kind of problem is very common when using vue and doing measurements of child-components.

How to disable scroll animation with scrollTo()

Is there a way to disable scroll animation when I set scroll position with scrollTo()?

Like.. when I do .

this.$refs.Scrollbar.scrollToY(1000)

My window scroll to the position as if someone is scrolling to the location manually. Is there a way to disable it, and instead jump to the scroll location?

when i use it with element.ui, it will disabled the submenu folding animate

the element.ui demo http://element.eleme.io/#/zh-CN/component/menu

I using this UI framework, and vue2-scrollbar, but the nav menu animate is stop.

<vue-scrollbar
    custom-class="my-scrollbar"
    ref="Scrollbar"
    :style="'height:' + menuHeight + 'px;'">
      <el-row class="tac">
  <el-col :span="8">
    <h5>带 icon</h5>
    <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose">
      <el-submenu index="1">
        <template slot="title"><i class="el-icon-message"></i>导航一</template>
        <el-menu-item-group>
          <template slot="title">分组一</template>
          <el-menu-item index="1-1">选项1</el-menu-item>
          <el-menu-item index="1-2">选项2</el-menu-item>
        </el-menu-item-group>
        <el-menu-item-group title="分组2">
          <el-menu-item index="1-3">选项3</el-menu-item>
        </el-menu-item-group>
        <el-submenu index="1-4">
          <template slot="title">选项4</template>
          <el-menu-item index="1-4-1">选项1</el-menu-item>
        </el-submenu>
      </el-submenu>
      <el-menu-item index="2"><i class="el-icon-menu"></i>导航二</el-menu-item>
      <el-menu-item index="3"><i class="el-icon-setting"></i>导航三</el-menu-item>
    </el-menu>
  </el-col>
  <el-col :span="8">
    <h5>不带 icon</h5>
    <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" theme="dark">
      <el-submenu index="1">
        <template slot="title">导航一</template>
        <el-menu-item-group title="分组一">
          <el-menu-item index="1-1">选项1</el-menu-item>
          <el-menu-item index="1-2">选项2</el-menu-item>
        </el-menu-item-group>
        <el-menu-item-group title="分组2">
          <el-menu-item index="1-3">选项3</el-menu-item>
        </el-menu-item-group>
        <el-submenu index="1-4">
          <template slot="title">选项4</template>
          <el-menu-item index="1-4-1">选项1</el-menu-item>
        </el-submenu>
      </el-submenu>
      <el-menu-item index="2">导航二</el-menu-item>
      <el-menu-item index="3">导航三</el-menu-item>
    </el-menu>
  </el-col>
  <el-col :span="8">
    <h5>分组</h5>
    <el-menu mode="vertical" default-active="1" class="el-menu-vertical-demo">
      <el-menu-item-group title="分组一">
        <el-menu-item index="1"><i class="el-icon-message"></i>导航一</el-menu-item>
        <el-menu-item index="2"><i class="el-icon-message"></i>导航二</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="分组二">
        <el-menu-item index="3"><i class="el-icon-message"></i>导航三</el-menu-item>
        <el-menu-item index="4"><i class="el-icon-message"></i>导航四</el-menu-item>
      </el-menu-item-group>
    </el-menu>
  </el-col>
</el-row>
    </vue-scrollbar>

Flexible height with percentages

Hi, is it possible to make this work with a flexible height?
I am trying to do this with vue2-scrollbar now, so I have 3 flexboxes, 2 have a height set. The third should be flexible and should get the scrollbar when it no longer fits the screen.

So what my question comes down to: "Is setting a max-height required or is there a work-around?"

can't get it to work here

Hi
I have trouble getting the component to work.And I don't know the reason.
I just started a brand new vue template with vue-cli ,then installed the vue2-scrollbar via npm command and subsituted the content in Hello.vue with the following code.

<template>
  <div>
    <vue-scrollbar custom-class="my-scrollbar" ref="Scrollbar">
      <div class="scroll-me">
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="kolom"></div>
        <div class="clearfix"></div>
      </div>
    </vue-scrollbar>
  </div>
</template>

<script>

  import VueScrollbar from 'vue2-scrollbar'
  require('../../node_modules/vue2-scrollbar/dist/style/vue2-scrollbar.css')

  // It's required to set min height of the scrollbar wrapper
  require('../../node_modules/vue2-scrollbar/dist/style/app.css')

  export default {
    components: { VueScrollbar }
  }

</script>

Finally, I ran "npm run dev".All I get is a block without scrollbar, what's wrong with my steps?
Thanks in Advance.

EDIT:Here is the screenshot.http://imgur.com/a/4xm8u

how to show the bar when I initialize it

Hi
In you demo, the scrollbar is always showing. But in my project, The scrollbar only display when I scrolling, I want it to be displayed when the component was initialized for the first time. What should I do?
Thank you!

how to let the scrollToY to the bottom

is there some api such as scrollToY(‘bottom’) or scrollToBottom , i have a chatting list , its item is coming from websocket in mounted hook , and i want to scroll it to bottom when i send or receive new message

Should propagate events to parent node when not scrolled

Hi @BosNaufal, thanks for your work!

I'm facing 2 problems when using vue2-scrollbar:

  1. If the content is shorter than the wrapper, you cannot scroll the body when your mouse is on the wrapper
  2. When the content is already at top of the wrapper, you cannot scroll the body upwards when your mouse is on the wrapper. The same thing happens when content at bottom and scroll down.

I've read the source code briefly, seems these can be fixed by deferring the calls of e.preventDefault() and e.stopPropagation() until the calculation in normalizeVertical()ended.

table tbody scrollbar

hello, how to add scrollbar to only tbody not all table? if i add then table is broken! thank you!

Detect when scroll is not needed

I want to hide the scrollbar when there's not enough content for the scroll to be needed but I don't see a way to detect when this is happening.

Vertical scroll

I am not able to add vertical scroll, it is only showing horizontal scroll.

image

Feature request: custom tag

First of all: thank you very, very much for your plugin!! Awesome!

I would find it awesome, if there was a possibility to define the tag of the scroller-wrapper. Currently, it will always be a div, right? But wouldn't it be great to have the possibility to define if it was a section or an aside or whatever element? That would improve HTML structure...

Auto Scroll to bottom

Hi, is there any event or feateure to handle autoscroll in the component? any hint maybe?
Currently im usign ].scrollToY(value), but whatever the value i placed, never is going to the last element in the div for scroll.
Thanks

improve scroll on a children component

it's necessary understand the context when scroll happen

ex:
component with plugin - parent
component with plugin - child

when you scroll child, scroll just this one and not the both

(congrats for your plugin, is the best one scroller on vue ecosystem, peviously I used nanoScroller, do you know? It was the best for me, but they require jQuery)

The second call on the same page doesn't work

I called the component two times on the same page, the first one was working well, but the second one did not work. And there was no error messages.

Is this component limited to the times of used on the same page?

Doesn't work on chrome

This component works well on Firefox and Edge , but it doesn't work on chrome. I just can't scroll when I use chrome and I see no errors in my console.

How to detect if scrollbar is rendered?

Hi,

First of all great plugin and great work and many thanks for that!
But i encountered in small issue, I want to apply animation after scrollbar is rendered. Is there any way to detect if scrollbar is initialized and rendered within a Vue component?

Thanks!

Wrong CSS import path

It should be: require('vue2-scrollbar/dist/style/vue2-scrollbar.css').

Alternative form: import 'vue2-scrollbar/dist/style/vue2-scrollbar.css'.

Option to disable scrolling of parent container if at bottom of scroll

I have an infinite scrolling type component that utilizes vue2-scrollbar. Using the onMaxScroll hook, when I get to the max scroll I issue an ajax call for more data. The issue arises if the ajax call takes a bit to return the body will start handling the scroll events and move.

Can an option be added to stopPropagation for the scroll events so the body doesn't scroll?

RTL support

First thanks for the scrollbar, it's awesome.
I am having issue when i am trying to scroll horizontally.
The problem caused by wrapper rtl direction
Can you add RTL support

Cannot read property 'children' of undefined

I have used cards list inside scroll when clicked on router-link the following error occurred

error

The error reason is in line 857 in dist

scrollAreaHeight: $scrollArea.children[0].clientHeight,
scrollAreaWidth: $scrollArea.children[0].clientWidth,

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.