Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<link href="http://code.jquery.com/mobile/1.1.2/jquery.mobile-1.1.2.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.2/jquery.mobile-1.1.2.min.js"></script>
<link href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<meta charset="UTF-8" />
<title>jQuery UI Slider - Array of step values</title>
<!-- jQuery UI  |  http://jquery.com/  http://jqueryui.com/  http://jqueryui.com/docs/Theming  -->
<style type="text/css">body{font:62.5% Verdana,Arial,sans-serif}</style>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
</head>
<body>
<div id="slider" style="width:400px;margin:4em;"></div>
  <div id="anzBesucher">1000</div>
</body>
</html>
$(function() {
                var values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27];
                var slider = $("#slider").slider({
                    orientation: 'horizontal',
                    range: "max",
                    min: 1,
                    max: 27,
                    value: 7,
                    stepValues: values,
                    slide: function(event, ui) {
                        var value = findNearest(includeLeft, includeRight, ui.value);
                        slider.slider('values', 0, value);
                        
                        $("#anzBesucher").text(getRealValue(slider.slider('values', 0)));
                      //realValue = findRealValue(ui.value);
                      
                      //$("#anzBesucher").text(realValue);
                        
                        //return false;
                    },
                    change: function(event, ui) { 
                        //
                    }
                });
  
  function findRealValue(val)
  {
    return trueValues[val-1];
  }
                
                function findNearest(includeLeft, includeRight, value) {
                    var nearest = null;
                    var diff = null;
                    for (var i = 0; i < values.length; i++) {
                        if ((includeLeft && values[i] <= value) || (includeRight && values[i] >= value)) {
                            var newDiff = Math.abs(value - values[i]);
                            if (diff == null || newDiff < diff) {
                                nearest = values[i];
                                diff = newDiff;
                            }
                        }
                    }
                    return nearest;
                }
  
                function getRealValue(sliderValue) {
                    for (var i = 0; i < values.length; i++) {
                        if (values[i] >= sliderValue) {
                            return trueValues[i];
                        }
                    }
                    return 0;
                }
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers