vue-drag-scroller
TypeScript icon, indicating that this package has built-in type declarations

1.8.0 • Public • Published

Vue drag scroller ⚡️

image

npm version npm download npm license

This package help you drag to scroll easier🌟

Docs and demo

https://github.com/huynamboz/vue-drag-scroller/assets/38585889/20139bab-0004-4249-8826-70959f6dbc77

How to install🔖

NPM

npm install vue-drag-scroller

YARN

yarn add vue-drag-scroller

Usage🔖

Use with vue 3:
Register global:

import  { createApp }  from  'vue'
import VueDragScroller from  "vue-drag-scroller"
       
import App from  './App.vue'

const app  =  createApp(App)
app.use(VueDragScroller)
app.mount('#app')
  
// in component
<template>
	<div v-drag-scroller>
	</div>
</template>

Config🔖

Options:

you can pass options to directive like this:

<template>
    <div v-drag-scroller="options">
    </div>
</template>
Name Description Type Default
startScroll Trigger when start scroll Function null
endScroll Trigger when end scroll Function null
speed Speed of scroll Number 1

Binding value:

you can pass binding value to directive like this:

<template>
    <div v-drag-scroller.onlyX>
    </div>
</template>
Name Description Type Default
disablechild Disable drag scroll in all child Boolean false
drag-scroller-disable Disable drag scroll in particular child Boolean false
onlyX Only scroll in X axis Boolean false
onlyY Only scroll in Y axis Boolean false

Priority: disablechild > drag-scroller-disable > onlyX > onlyY

Events:

Name Description
startScroll Trigger when start scroll
endScroll Trigger when end scroll
onScrolling Trigger when drag and move mouse

Example

<script setup>
const onScroll = (e) => {
  console.log("working",e);
};

const onEndScroll = (e) => {
  console.log("end scroll",e);
};

const options = {
    startScroll: onScroll,
    endScroll: onEndScroll,
};

</script>

// in component 
<template>
    <div v-drag-scroller="options">
    </div>
</template>
  • Drag parent except all child

Example

<template>
    <div v-drag-scroller.disablechild>
        <div class="child">
        </div>
        <div class="child">
        </div>
    </div>
</template>
  • Drag parent except particular child

Example

<template>
    <div v-drag-scroller>
        <div class="child" drag-scroller-disable> // disable drag scroll
        </div>
        <div class="child">
        </div>
    </div>
</template>
  • Only scroll in X axis

Example

<template>
    <div v-drag-scroller.onlyX>
    </div>
</template>
  • Only scroll in Y axis

Example

<template>
    <div v-drag-scroller.onlyY>
    </div>
</template>
  • Hide scrollbar

Example

<template>
    <div v-drag-scroller={
      hideScrollbar: true
    }>
    </div>
</template>
  • Change speed of scroll

Example

<template>
    <div v-drag-scroller={
      speed: 0.5 // default is 1
    }>
    </div>
</template>
  • Change direction of scroll

Example

<template>
    <div v-drag-scroller={
      reverseDirection: true
    }>
    </div>
</template>
  • Events Listener with v-on or @

Example with @

<template>
    <div v-drag-scroller
      @scrollStart="onScroll"
      @scrollEnd="onEndScroll"
      @scrollMoving="onScrolling"
    >
    </div>
</template>

Example with v-on

<template>
    <div v-drag-scroller
      v-on:scrollStart="onScroll"
      v-on:scrollEnd="onEndScroll"
      v-on:scrollMoving="onScrolling"
    >
    </div>
</template>

Package Sidebar

Install

npm i vue-drag-scroller

Weekly Downloads

7

Version

1.8.0

License

MIT

Unpacked Size

2.17 MB

Total Files

21

Last publish

Collaborators

  • huynamvn