I have a div which displays the current value of the slider and the div moves with the slider position.
Based on the answer at http://stackoverflow.com/questions/745037/using-offset-and-jquery-slider
I came up with the following code:
function SliderSetup()
{
$("#slider").slider({
value:0,
min: -10,
max: 10,
step: 2,
animate:false,
slide: function(event, ui) {
setTimeout(showVal, 10);
}
});
$("#slider").slider("value", 0);
showVal(); //setTimeout(showVal, 10) does not work either
}
function showVal() {
var position = $('.ui-slider-handle:first').position(); //i tried offset()-didnt work
var value = $('#slider').slider('value');
$('#value1').text(value).css({'left':position.left});
}
The div position is correct when the user uses the slider, but by default the value is not in the correct position. Screenshot below
Edit: Markup
<tr>
<td width="30%">
<h2>
Select Value</h2>
</td>
<td width="60%">
<div id="value1"> </div>
<div id="slider">
</div>
</td>
<td>
<div id="myDiv">
</div>
</td>
</tr>