Search code examples
javascriptjqueryjquery-uijquery-slider

Changing the default slider JQ UI


With JQ UI I created a standard slider. I found out how to change some of its parameters: size, min.size, the maximum, etc. but never found a place put a picture. That is: change the slider.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Slider - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<style>
#slider-vertical {
    height: 600px;
    background-color: #0F3;
}
</style>
<script>
$(function () {
    $("#slider-vertical").slider({
        orientation: "vertical",
        range: "min",
        min: 0,
        max: 100,
        value: 60,
        slide: function (event, ui) {
            $("#amount").val(ui.value);
        }
    });
});
</script>
</head>
<body>
<div id="slider-vertical"></div>
</body>
</html>

Solution

  • If you mean changing the green area to an image instead, you can change background-color to background-image or just background and then put give it the URL or location of the image you want. Demo here

    #slider-vertical {
        height: 600px;
        background: url(backgroundImage.jpg);
    }
    

    If you want it to be both above and below the slider, you can do it by giving .ui-slider-range a transparent background like so

    .ui-slider-range {
        /* If you want the same image as the top part of the slider. */
        /* Otherwise you can change the bottom portion here */
      background:transparent;
    }
    

    Demo here