Slider with label and tooltip

Slider with label and tooltip

HTML

<div id="slider-val"></div>
<div id="slider"></div>

CSS

#slider label {
    position: absolute;
    width: 20px;
    margin-left: -10px;
    text-align: center;
    margin-top: 20px;
}

/* below is not necessary, just for style */
#slider {
    width: 95%;
    margin: 2em auto;
}

.tooltip-slider {
    position: absolute;
  
    display: block;
    padding: 5px;
    font-size: 11px;
    visibility: visible;
    margin-top: -2px;
    bottom:120%;
    margin-left: -8px;
}

.tooltip-slider .tooltip-slider-arrow {
    bottom: 0;
    left: 50%;
    margin-left: -5px;
    border-top: 5px solid #000000;
    border-right: 5px solid transparent;
    border-left: 5px solid transparent;
    position: absolute;
    width: 0;
    height: 0;
}

.tooltip-slider-inner {
    max-width: 200px;
    padding: 3px 8px;
    color: #ffffff;
    text-align: center;
    text-decoration: none;
    background-color: #000000;
    -webkit-border-radius: 4px;
       -moz-border-radius: 4px;
            border-radius: 4px;
}

JavaScript

var initialValue = 0;

var sliderTooltip = function(event, ui) {
    var tooltip;
    var curValue = ui.value || initialValue;
    if(curValue!=0 && curValue<100){
        tooltip = '<div class="tooltip-slider"><div class="tooltip-slider-inner">' + curValue + 'K</div><div class="tooltip-slider-arrow"></div></div>';
    }
    else if(curValue==100) {
         tooltip = '<div class="tooltip-slider"><div class="tooltip-slider-inner">1L</div><div class="tooltip-slider-arrow"></div></div>';
    }   
    else{
            tooltip = '<div class="tooltip-slider"><div class="tooltip-slider-inner">' + curValue + '</div><div class="tooltip-slider-arrow"></div></div>';
        }
        
    $('.ui-slider-handle').html(tooltip);
}

$( "#slider" ).slider({
		range: "min",
		value: initialValue,
		min: 0,
		max: 100,
		step: 5,
    create: sliderTooltip,
    slide: sliderTooltip    
})
.each(function() {

  //
  // Add labels to slider whose values 
  // are specified by min, max and whose
  // step is set to 1
  //

  // Get the options for this slider
  var opt = $(this).data().uiSlider.options;
  // Get the number of possible values
  var vals = opt.max - opt.min;
  // Space out values
  for (var i = 0; i <= vals; i+=10) {
      var el;
      if(i!=0 && i<100){
         el = $('<label>'+(i+0)+'K</label>').css('left',(i/vals*100)+'%'); 
      }
      else if(i==100)
      el = $('<label>1L</label>').css('left',(i/vals*100)+'%');
      else
      {
          el =  $('<label>'+(i+0)+'</label>').css('left',(i/vals*100)+'%');
      }
    
    $( "#slider" ).append(el);
  }
});