Volume ui slider bar icon bug fix

The volume slide bar fix is to add change: function and call the background position for the icon separately for the slider and change

by manu v

HTML

<section>	<span class="tooltip"></span> 
    <!-- Tooltip -->
    <div id="slider"></div>
    <!-- the Slider -->	<span class="volume"></span> 
    <!-- Volume -->
</section>

CSS

body {
    background: url('http://media02.hongkiat.com/jquery-ui-slider/demo/images/bg.jpg') repeat top left;
}
section {
    width: 150px;
    height: auto;
    margin: 100px auto 0;
    position: relative;
}
#slider {
    border-width: 1px;
    border-style: solid;
    border-color: #333 #333 #777 #333;
    border-radius: 25px;
    width: 100px;
    position: absolute;
    height: 13px;
    background-color: #8e8d8d;
    background: url('http://media02.hongkiat.com/jquery-ui-slider/demo/images/bg-track.png') repeat top left;
    box-shadow: inset 0 1px 5px 0px rgba(0, 0, 0, .5), 0 1px 0 0px rgba(250, 250, 250, .5);
    left: 20px;
}
.tooltip {
    position: absolute;
    display: block;
    top: -25px;
    width: 35px;
    height: 20px;
    color: #fff;
    text-align: center;
    font: 10pt Tahoma, Arial, sans-serif;
    border-radius: 3px;
    border: 1px solid #333;
    -webkit-box-shadow: 1px 1px 2px 0px rgba(0, 0, 0, .3);
    box-shadow: 1px 1px 2px 0px rgba(0, 0, 0, .3);
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background: -moz-linear-gradient(top, rgba(69, 72, 77, 0.5) 0%, rgba(0, 0, 0, 0.5) 100%);
    /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(69, 72, 77, 0.5)), color-stop(100%, rgba(0, 0, 0, 0.5)));
    /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, rgba(69, 72, 77, 0.5) 0%, rgba(0, 0, 0, 0.5) 100%);
    /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, rgba(69, 72, 77, 0.5) 0%, rgba(0, 0, 0, 0.5) 100%);
    /* Opera 11.10+ */
    background: -ms-linear-gradient(top, rgba(69, 72, 77, 0.5) 0%, rgba(0, 0, 0, 0.5) 100%);
    /* IE10+ */
    background: linear-gradient(top, rgba(69, 72, 77, 0.5) 0%, rgba(0, 0, 0, 0.5) 100%);
    /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8045484d', endColorstr='#80000000', GradientType=0);
    /* IE6-9 */
}
.volume {
    content:"";
   ...

JavaScript

$(function () {

    //Store frequently elements in variables
    var slider = $('#slider'),
        tooltip = $('.tooltip');

    //Hide the Tooltip at first
    tooltip.hide();

    //Call the Slider
    slider.slider({
        //Config
        range: "min",
        min: 1,
        value: 35,

        start: function (event, ui) {
            tooltip.fadeIn('fast');
        },

        change: function (event, ui) {
            var value = slider.slider('value');
            setVolumeImage(value);
        },

        //Slider Event
        slide: function (event, ui) { //When the slider is sliding

            var value = slider.slider('value');
            setVolumeImage(value);
            tooltip.css('left', value).text(ui.value); //Adjust the tooltip accordingly
        },

        stop: function (event, ui) {
            tooltip.fadeOut('fast');
        }
    });


    function setVolumeImage(value) {
        volume = $('.volume');
        if (value <= 5) {
            volume.css('background-position', '0 0');
        } else if (value <= 25) {
            volume.css('background-position', '0 -25px');
        } else if (value <= 75) {
            volume.css('background-position', '0 -50px');
        } else {
            volume.css('background-position', '0 -75px');
        }
    }
});