Vue range slider

Drag the slider : Totally useless vue range slider

Made with

Html
Css/SCSS
Javascript

Html

<div id="app">
  <h1>Drag the slider. Totally useless vue range slider</h1>
  <div class="slidecontainer">
    <input type="range" min="1" max="100" v-model="sliderValue" @input="changeWidth" class="slider" id="myRange">
  </div>
  <div class="box" v-bind:style="{width: computedWidth, backgroundColor: computedColor}">
    {{ width }}%
  </div>
</div>

Css

h1{
  font-family:'Arial';
  text-align:center;
}
.box{
  width: 50%;
  height:100px;
  background:#000;
  color:#fff;
  font-size: 2em;
  text-align:center;
  padding-top: 50px;
  font-family:'Arial';
  font-weight: bold;
}
/* The slider itself */
.slider {
    -webkit-appearance: none;  /* Override default CSS styles */
    appearance: none;
    height: 25px; /* Specified height */
    background: #d3d3d3; /* Grey background */
    outline: none; /* Remove outline */
    opacity: 0.7; /* Set transparency (for mouse-over effects on hover) */
    -webkit-transition: .2s; /* 0.2 seconds transition on hover */
    transition: opacity .2s;
}

/* Mouse-over effects */
.slider:hover {
    opacity: 1; /* Fully shown on mouse-over */
}

/* The slider handle (use -webkit- (Chrome, Opera, Safari, Edge) and -moz- (Firefox) to override default look) */ 
.slider::-webkit-slider-thumb {
    -webkit-appearance: none; /* Override default look */
    appearance: none;
    width: 25px; /* Set a specific slider handle width */
    height: 25px; /* Slider handle height */
    background: #4CAF50; /* Green background */
    cursor: pointer; /* Cursor on hover */
}

.slider::-moz-range-thumb {
    width: 25px; /* Set a specific slider handle width */
    height: 25px; /* Slider handle height */
    background: #4CAF50; /* Green background */
    cursor: pointer; /* Cursor on hover */
}

Javascript

var vm = new Vue({
  el: '#app',
  data:{
    sliderValue:50,
    width: 50
  },
  computed:{
   computedWidth(){
     return this.width + '%';
   },
    computedColor(){
      return `rgba(${this.width},${this.width * 2},${this.width * 1.2})`
    }
  },
  methods:{
    changeWidth(){
      this.width = this.sliderValue
    }
  }
})

Author

Dragos Nedelcu

Demo

See the Pen Vue range slider by Dragos Nedelcu (@dragos193) on CodePen.