1. v-ctrl
An Vue abstract component for mouse dragging, i.e. the pattern below:
v-ctrl
Package: v-ctrl
Created by: v-comp
Last modified: Tue, 28 Jun 2022 07:58:16 GMT
Version: 1.1.0
License: MIT
Downloads: 489
Repository: https://github.com/v-comp/v-ctrl

Install

npm install v-ctrl
yarn add v-ctrl

v-ctrl

An Vue abstract component for mouse dragging, i.e. the pattern below:

--down--move--move---move--...---up--|-->

Install

 npm install --save v-ctrl

# or
yarn add v-ctrl

Or just add a script tag in you html:

 <script src="https://unpkg.com/v-ctrl"></script>

Demo

A simple range slider:

 <template>
  <div class="wrapper">
    <v-ctrl direction="h" :throttle="80" @change="onChange">
      <div class="range-slider">
        <div class="progress" :style="{ width: percentage }"></div>
        <div class="thumb" :style="{ left: percentage }"></div>
      </div>
    </v-ctrl>
    <p>{{value}}</p>
  </div>
</template>

<script>
  import VCtrl from 'v-ctrl'

  export default {
    components: {
      'v-ctrl': VCtrl
    },
  
    data () {
      return { value: 20 }
    },
  
    computed: {
      percentage () {
        return `${this.value}%`
      }
    },
  
    methods: {
      onChange (val) {
        this.value = Math.round(val * 100)
      }
    }
  }
</script>

Live demo

Attributes

throttle: Number

Throttling time for mousemove.

direction: Enum('v', 'h', 'vh')

  • h: emit proportion for the horizontal axis, e.g. 0.52
  • v: emit proportion for the vertical axis, e.g 0.91
  • vh: emit proportion for both axis, e.g. { x: 0.24, y: 0.87 }

Event

change

change event is emitted while keeping dragging.

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code