1.0.0 • Published 4 years ago

@serh/vue-roundslider v1.0.0

Weekly downloads
1
License
BSD-3-Clause
Repository
github
Last release
4 years ago

vue-roundslider

Round slider (can call as Circle slider or Knob slider) component allows the user to select a value or range of values through a circular dial.

Demo

alt Image slider

How to install

npm i @serh/vue-roundslider --save

Example

<template>
  <div>
    <VueRoundslider
      :duration="duration"
      :position="position"
      :diametr="300"
      :widthCircle="10"
      :colorLine="colorLine"
      :onPosition="eventPosition"
      :onMouseMoveCenter="eventMouseMoveCenter"
      :onMouseClickCenter="eventMouseClickCenter"
      :onMouseMovePosition="eventMouseMovePosition"
    ></VueRoundslider>
  </div>
</template>

<script>
import VueRoundslider from "@serh/vue-roundslider";
const COLOR_LINE_DEFAULT = "green";
const COLOR_LINE_END = "blue";
export default {
  data: () => ({
    duration: 20,
    position: 5,
    colorLine: COLOR_LINE_DEFAULT,
    timerInterval: null,
    mouseMoveCenter: false,
  }),
  watch: {
    position: function (val) {
      if (val >= this.duration) {
        clearInterval(this.timerInterval);
        this.timerInterval = null;
        this.colorLine = COLOR_LINE_END;
      } else {
        this.colorLine = COLOR_LINE_DEFAULT;

        if (!this.timerInterval) {
          this.positionInterval();
        }
      }
    },
    mouseMoveCenter: function (val) {
      if (val === true) {
        console.log("Mouse over center");
      } else {
        console.log("Mouse out center");
      }
    },
  },
  mounted() {
    this.positionInterval();
  },
  components: {
    VueRoundslider,
  },
  methods: {
    positionInterval() {
      this.timerInterval = setInterval(() => (this.position += 1), 1000);
    },
    eventPosition(position) {
      this.position = position;
    },
    eventMouseMoveCenter(event) {
      this.mouseMoveCenter = true;
    },
    eventMouseMovePosition(event) {
      this.mouseMoveCenter = false;
    },
    eventMouseClickCenter(event) {
      console.log("Click Center");
    },
  },
};
</script>

<style scoped lang="scss">
</style>

Props

nametypedefaultdescription
durationNumber100The url of the sound to play.The max property indicates the maximum value of the slider.
diametrNumber100Indicates diametr of the slider.
widthCircleNumber7Width of the drawn line
colorLineStringgreenColor of the drawn line
positionNumber0Current position slider
onPositionFunctionfunction(){}Callback function when slider changes
onMouseMoveCenterFunctionfunction(){}Callback function when mouse over center
onMouseClickCenterFunctionfunction(){}Callback function when mouse click center
onMouseMovePositionFunctionfunction(){}Callback function when move change position
formatTimeBooleantrueFormat duration output how time