Skip to content

Instantly share code, notes, and snippets.

@keyserfaty
Created February 1, 2019 03:42
Show Gist options
  • Save keyserfaty/61e72badbc2d3c9978f0c3a472095d4c to your computer and use it in GitHub Desktop.
Save keyserfaty/61e72badbc2d3c9978f0c3a472095d4c to your computer and use it in GitHub Desktop.
slider js
var max = 500000;
$(document).ready(function(){
var slider = $('.slider');
var output = $('.output');
var sliderRight = $('.slider-right');
function getPercentage (val) {
return val * 50 / max;
}
function getSliderRightWidth (val) {
return 100 - getPercentage(val) + '%';
}
function GetValueFromRange(sli, out){
sli.on('input', function(){
console.log(getPercentage(sli.val()))
value = sli.val()
out.text(value + '$');
sliderRight.css('width', getSliderRightWidth(value));
})
}
var value = slider.val()
output.html(value + '$');
GetValueFromRange(slider, output);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment