NightCatSama/vue-slider-component

Get position on slider on click

Opened this issue · 3 comments

Describe the feature

When clicking on the slider (particularly when clickable is false), return the position through a click event. This lets you add a marker to the slider at the position that the user clicks.

Describe the solution you'd like

Emit a click event that returns the position on the slider

<template>
  <vue-slider v-model="value" @click="onClick" />
</template>

<script>
import VueSlider from 'vue-slider-component'
import 'vue-slider-component/theme/antd.css'

export default {
  components: {
    VueSlider
  },
  data () {
    return {
      value: 0
    }
  },
  methods: {
    onClick(position) {
      console.log(position)
    }
  }
}
</script>

click is a browser native event, you can get the current position of the element through event.target.

Right, but I'm looking for the position on the slider when clicked. For example, if the slider has a range from 0 to 1, and I click in the middle, I should get the value 0.5. I submitted a pull request that resolves this request.

NightCatSama gave a great example of how this can be done without this feature. Adding it here in case anyone wants to do the same thing.

<vue-slider ref="slider" @click.native="handleClick" />

handleClick(e) {
  const sliderVM = this.$refs.slider;
  sliderVM.setScale();
  const pos = sliderVM. getPosByEvent(e);
}