An Vue abstract component for mouse dragging, i.e. the pattern below:
--down--move--move---move--...---up--|-->
npm install --save v-ctrl
# or
yarn add v-ctrlOr just add a script tag in you html:
<scriptsrc="https://unpkg.com/v-ctrl"></script>A simple range slider:
<template><divclass="wrapper"><v-ctrldirection="h" :throttle="80" @change="onChange"><divclass="range-slider"><divclass="progress" :style="{ width: percentage }"></div><divclass="thumb" :style="{ left: percentage }"></div></div></v-ctrl><p>{{value}}</p></div></template><script>importVCtrlfrom'v-ctrl'exportdefault{components: {'v-ctrl': VCtrl},data(){return{value: 20}},computed: {percentage(){return`${this.value}%`}},methods: {onChange(val){this.value=Math.round(val*100)}}}</script>Throttling time for mousemove.
h: emit proportion for the horizontal axis, e.g.0.52v: emit proportion for the vertical axis, e.g0.91vh: emit proportion for both axis, e.g.{ x: 0.24, y: 0.87 }
change event is emitted while keeping dragging.