All Projects → donmbelembe → Vue Dragscroll

donmbelembe / Vue Dragscroll

Licence: mit
A vue directive to make a scrollable element scroll by draging to the scroll direction

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Dragscroll

Vue Chimera
VueJS reactive RESTful API
Stars: ✭ 160 (-8.57%)
Mutual labels:  vuejs2, vue-plugin
Vue Emoji Picker
Very simple, yet powerful, vue emoji picker 🎉🔥🚀
Stars: ✭ 218 (+24.57%)
Mutual labels:  vuejs2, vue-plugin
Vue Codemirror
⌨️ @codemirror component for @vuejs
Stars: ✭ 2,115 (+1108.57%)
Mutual labels:  vuejs2, vue-plugin
Vuet
允许你定义飙车过程的集中式状态管理模式
Stars: ✭ 430 (+145.71%)
Mutual labels:  vuejs2, vue-plugin
Vue Scroll Progress Bar
Vue.js plugin for page scroll progress bar
Stars: ✭ 76 (-56.57%)
Mutual labels:  vuejs2, vue-plugin
Vue Ellipse Progress
A Vue.js component to create beautiful animated circular progress bars
Stars: ✭ 101 (-42.29%)
Mutual labels:  vuejs2, vue-plugin
Vuent
🎨 Vue.js components implementing Microsoft Fluent Design
Stars: ✭ 207 (+18.29%)
Mutual labels:  vuejs2, vue-plugin
Vue Touch Ripple
👆 Touch ripple component for @vuejs
Stars: ✭ 443 (+153.14%)
Mutual labels:  vuejs2, vue-plugin
Vue Quill Editor
🍡@quilljs editor component for @vuejs
Stars: ✭ 6,874 (+3828%)
Mutual labels:  vuejs2, vue-plugin
Vue Toastr
Vuejs Toast : Plugin and Component Capability.
Stars: ✭ 93 (-46.86%)
Mutual labels:  vuejs2, vue-plugin
Vue Awesome Swiper
🏆 Swiper component for @vuejs
Stars: ✭ 12,072 (+6798.29%)
Mutual labels:  vuejs2, vue-plugin
Vue Barcode
Barcode generator for Vue.js
Stars: ✭ 164 (-6.29%)
Mutual labels:  vuejs2
Vue Info Card
Simple and beautiful card component with an elegant spark line, for VueJS.
Stars: ✭ 159 (-9.14%)
Mutual labels:  vuejs2
Vue Objccn
🔥 Use Vue.js to develop a cross-platform full stack application / 用 Vue.js 开发的跨三端应用
Stars: ✭ 1,993 (+1038.86%)
Mutual labels:  vuejs2
Glue
Configure Vue.js components using ClojureScript, manage global state using Atoms.
Stars: ✭ 164 (-6.29%)
Mutual labels:  vuejs2
Vuetify Todo Pwa
✔️ A simple Todo PWA built with Vue CLI 3 + Vuex + Vuetify.
Stars: ✭ 160 (-8.57%)
Mutual labels:  vuejs2
Pendulum
A simple markdown editor for static files (Hugo, Nexo, Jekyll, MkDocs, ...)
Stars: ✭ 157 (-10.29%)
Mutual labels:  vuejs2
Vs
Vue Visualisation Package using d3.js and leaflet.
Stars: ✭ 157 (-10.29%)
Mutual labels:  vuejs2
Vue Atlas
A Vue.js 2 UI component library.
Stars: ✭ 173 (-1.14%)
Mutual labels:  vuejs2
Vue Orgchart
🌿 Vue.js wrapper for OrgChart.js
Stars: ✭ 167 (-4.57%)
Mutual labels:  vuejs2

vue-dragscroll (Documentation)

vue-dragscroll is a micro vue.js directive which enables scrolling via holding the mouse button ("drag and drop" or "click and hold" style, online demo).

Installation

Via npm

$ npm install vue-dragscroll

Then, in your JavaScript file:

// Register dragscroll globally
import VueDragscroll from 'vue-dragscroll'
Vue.use(VueDragscroll)

// Or, register it locally in a component
import { dragscroll } from 'vue-dragscroll'
export default {
  name: 'MyComponent',
  directives: {
    'dragscroll': dragscroll
  },
}

Via cdn

Download the and unpack distribution

<script src="path/to/vue-dragscroll.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/vue-dragscroll"></script>

Usage

Add the v-dragscroll directive to a scrollable element:

<div v-dragscroll>
    Big text goes here...
</div>

That's it! Now you can scroll it by dragging.

Keep in mind that now it is not possible to select the content with mouse, so apply the cursor: default; CSS style to prevent confusing the users (or even cursor: grab; in case the content is not a text).

/* EXEMPLE */
.grab-bing {
  cursor : -webkit-grab;
  cursor : -moz-grab;
  cursor : -o-grab;
  cursor : grab;
}


.grab-bing:active {
  cursor : -webkit-grabbing;
  cursor : -moz-grabbing;
  cursor : -o-grabbing;
  cursor : grabbing;
}

You can also add the :nochilddrag argument to the v-dragscroll, which will only enable drag-scrolling for an element itself, but not for its subchildren. This can be usefull, if you want to enable the scrolling the area by dragging its empty space, but keep the opportunity to select the text (see example).

<div v-dragscroll:nochilddrag>
  ...content
</div>

If you wish to handle enable/disable dragscrolling, you can pass a boolean as value (This doesn't apply for mobile)

<div v-dragscroll="false">
  ...content
</div>

If you wish to scroll only Vertically or Horizotally, you can use x or y modifiers.

<div v-dragscroll.x="true">
  ...content
</div>
<div v-dragscroll.y="true">
  ...content
</div>

Select which elements can be dragged (data attributes method)

<div v-dragscroll> 
  <div class="child">...<div><!-- can be dragged -->
  <div class="child" data-no-dragscroll>...<div><!-- can't be dragged -->
<div>

<div v-dragscroll:nochilddrag> 
  <div class="child" data-dragscroll>...<div><!-- can be dragged -->
  <div class="child">...<div><!-- can't be dragged -->
<div>

Firstchilddrag (DEPRECATED, prefer data attributes)

<div v-dragscroll:firstchilddrag> 
    <div class="subContainer">...<div> 
  <div>

It would be helpful if scroll were passed to the window object, when max scroll position were reached, you can use pass modifier.

<div v-dragscroll.pass>
  ...content
</div>

when the scroll is passed not to the window, but to another scroll context, you can specify the element to pass the scrolling to.

<div v-dragscroll.pass="{container: '.my-scroll-container'}">
  ...content
</div>

If you want to apply dragscroll to a child dom element you have no control over (because generated by vuejs). You can use v-dragscroll="{ target: 'element' }" to tell to which child the directive will be applied.

<!-- Vue -->
<mycomponent v-dragscroll="{ target: '.my-draggable-div' }">
  ...content
</mycomponent>

<!-- HTML generated -->
<div class="mycomponent">
  <div class="my-draggable-div">
    ...content
  </div>
</div>

In this case to control if drag should be enabled/disabled you can add the active parameter.

<mycomponent v-dragscroll="{ target: '.my-draggable-div', active: true }">
  ...content
</mycomponent>

If you wish to ignore specific mouse buttons, you can use the following modifiers.

  • noleft
  • nomiddle
  • noright
  • noback
  • noforward
<div v-dragscroll.noleft="true">
  ...content
</div>
<div v-dragscroll.noback.noforward="true">
  ...content
</div>

Events

The directive provides 3 events.

  • dragscrollstart
  • dragscrollmove
  • dragscrollend

The dragscrollmove event includes a data object with the following format:

{
  detail: {
    deltaX: 0, // if using the x modifier, or no axis modifier
    deltaY: 0, // if using the y modifier, or no axis modifier
  },
}

Example:

<div
  v-dragscroll
  v-on:dragscrollstart="doSomething"
  v-on:dragscrollmove="doSomething(params, $event.detail.deltaX)"
  v-on:dragscrollend="doSomething"
>
..Content
<div>

Follow me on twitter: https://twitter.com/don_jon243

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].