Drag the slider above. More demos can be found here.
Simple Slider is a jQuery plugin which allows your users to select a value from a numerical range by simply dragging a slider.
data-slider="true" on any input
Include jQuery and the Simple Slider JavaScript and CSS files on your page,
then activate Simple Slider on your text input using the data-slider attribute:
<!-- Include jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- Include Simple Slider JavaScript and CSS -->
<script src="yourfiles/simple-slider.js"></script>
<link href="yourfiles/simple-slider.css" rel="stylesheet" type="text/css" />
<!-- Activate Simple Slider on your input -->
<input type="text" data-slider="true">
You can also manually turn any text input into a Simple Slider in JavaScript as follows:
$("#my-input").simpleSlider();
The value the user selects with the slider is immediately available inside the
value attribute of the text input you attached the slider to. This means you
can include Simple Slider in your HTML forms and the the selected value will
automatically be send to your server when the form is submitted.
If you would like to get the slider’s value using javascript, you can register
for the slider:changed event:
$("#my-input").bind("slider:changed", function (event, data) {
// The currently selected value of the slider
alert(data.value);
// The value as a ratio of the slider (between 0 and 1)
alert(data.ratio);
});
You can configure Simple Slider by either using data-slider-* unobtrusive
javascript settings, or by passing in a configuration object when initializing
the plugin manually.
data-slider-range="10,1000"data-slider-step="100"data-slider-snap="true"data-slider-values="0,100,500,800,2000"data-slider-values. Eg. data-slider-equal-steps="true"data-slider-theme="volume"data-slider-highlight="true"You can bind to the following jQuery events using bind, for example:
$("#my-input").bind("slider:ready", function (event, data) { ... })
All Simple Slider events pass 2 parameters into your function, event and
data. event is a regular jQuery event object. data contains the
following properties:
selector.simpleSlider("setValue", value);selector.simpleSlider("setRatio", ratio);Please report any bugs or feature requests on the github issues page for this project here:
https://github.com/loopj/jquery-simple-slider/issues
Simple Slider is released under the MIT license.
James Smith, British entrepreneur and developer based in San Francisco.
I'm the co-founder of Bugsnag with Simon Maynard, and from 2009 to 2012 I led up the product team as CTO of Heyzap.