I\'d like to modify the sliders on-the-fly. I tried to do so by using
$(\"#slider\").slider(\"option\", \"values\", [50,80]);
This call wil
One part of @gaurav solution worked for jQuery 2.1.3 and JQuery UI 1.10.2 with multiple sliders. My project is using four range sliders to filter data with this filter.js plugin. Other solutions were resetting the slider handles back to their starting end points just fine, but apparently they were not firing an event that filter.js understood. So here's how I looped through the sliders:
$("yourSliderSelection").each (function () {
var hs = $(this);
var options = $(this).slider('option');
//reset the ui
$(this).slider( 'values', [ options.min, options.max ] );
//refresh/trigger event so that filter.js can reset handling the data
hs.slider('option', 'slide').call(
hs,
null,
{
handle: $('.ui-slider-handle', hs),
values: [options.min, options.max]
}
);
});
The hs.slider()
code resets the data, but not the UI in my scenario. Hope this helps others.
Mal's answer was the only one that worked for me (maybe jqueryUI has changed), here is a variant for dealing with a range:
$( "#slider-range" ).slider('values',0,lowerValue);
$( "#slider-range" ).slider('values',1,upperValue);
$( "#slider-range" ).slider("refresh");
None of the above answers worked for me, perhaps they were based on an older version of the framework?
All I needed to do was set the value of the underlying control, then call the refresh method, as below:
$("#slider").val(50);
$("#slider").slider("refresh");
On start or refresh value = 0 (default) How to get value from http request
<script>
$(function() {
$( "#slider-vertical" ).slider({
animate: 5000,
orientation: "vertical",
range: "max",
min: 0,
max: 100,
value: function( event, ui ) {
$( "#amount" ).val( ui.value );
// build a URL using the value from the slider
var geturl = "http://192.168.0.101/position";
// make an AJAX call to the Arduino
$.get(geturl, function(data) {
});
},
slide: function( event, ui ) {
$( "#amount" ).val( ui.value );
// build a URL using the value from the slider
var resturl = "http://192.168.0.101/set?points=" + ui.value;
// make an AJAX call to the Arduino
$.get(resturl, function(data) {
});
}
});
$( "#amount" ).val( $( "#slider-vertical" ).slider( "value" ) );
});
</script>
It's possible to manually trigger events like this:
Apply the slider behavior to the element
var s = $('#slider').slider();
...
Set the slider value
s.slider('value',10);
Trigger the slide event, passing a ui object
s.trigger('slide',{ ui: $('.ui-slider-handle', s), value: 10 });
I wanted to update slider as well as the inputbox. For me following is working
a.slider('value',1520);
$("#labelAID").val(1520);
where a
is object as following.
var a= $( "<div id='slider' style='width:200px;margin-left:20px;'></div>" ).insertAfter( "#labelAID" ).slider({
min: 0,
max: 2000,
range: "min",
value: 111,
slide: function( event, ui ) {
$("#labelAID").val(ui.value );
}
});
$( "#labelAID" ).keyup(function() {
a.slider( "value",$( "#labelAID" ).val() );
});