| jquery
range sliders |
|
|
|
| For a range slider, all you
need to do is set range option to true |
|
| reference is : jquery-ui.js |
|
| HTML |
|
|
|
| Age : <span
id="spanOutput"></span> |
|
| <br /><br /> |
|
| <div
id="slider"></div> |
|
| <br /> |
|
| <label
for="txtMinAge">Minimum Age</label> |
|
| <input
id="txtMinAge" type="text" /> |
|
| <br /><br /> |
|
| <label
for="txtMaxAge">Maximum Age</label> |
|
| <input
id="txtMaxAge" type="text" /> |
|
|
|
| jQuery Code |
|
|
|
| $(document).ready(function ()
{ |
|
| var outputSpan = $('#spanOutput'); |
|
| var sliderDiv = $('#slider'); |
|
| |
|
| sliderDiv.slider({ |
|
| range: true, |
we get if we specify range, color mark if we move |
| min: 18, |
|
| max: 100, |
|
| values: [20, 30], |
after loads,normally minimum age and max age displays is 18 and 100 , if
we want to display to low, use values [20,30], used to struck at that age
minimu and maximum slide strucs |
| slide: function (event, ui) { |
event is slide, element that triggers event is ui |
| outputSpan.html(ui.values[0] + '
- ' + ui.values[1] + ' Years'); |
second one is ui.values- it gets the value from slider which is minimum
by sliding manually and loads that value to using html into outputspan |
| }, |
|
| stop: function (event, ui) { |
whenever we stop the sliding function, at that retrieve the value and
enter in minimum age and max age |
|
$('#txtMinAge').val(ui.values[0]); |
if we want dy |
|
$('#txtMaxAge').val(ui.values[1]); |
|
| } |
|
| }); |
|
| |
after loads it willdisplay asking what is the value at o and 1 at after
load and write to outout span using html method at before slider |
|
outputSpan.html(sliderDiv.slider('values', 0) + ' - ' |
after loads if we need in input text buttons whats is the minimum and
maximum age |
| + sliderDiv.slider('values', 1) + '
Years'); |
|
|
$('#txtMinAge').val(sliderDiv.slider('values', 0)); |
|
|
$('#txtMaxAge').val(sliderDiv.slider('values', 1)); |
after loads if we need in input text buttons whats is the minimum and
maximum age |
| }); |
|
|
|
|
|
|
|
|
|
|
|
| values |
| values[1] |
| slider |
| val |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
No comments:
Post a Comment