On Thu, Mar 12, 2009 at 12:25 PM, Chag <[email protected]> wrote:

>
>
> Hi,
>
> I'm trying to understand the slider in UI (I am not a good js coder). I've
> 2
> sliders and when I move one, i'd like get the position of the slider I
> juste
> moved. not the value but the 'left' percentage.
>
> here's my code :
>
> $('#slider0').slider({
>        range: true,
>        animate: true,
>        values: [17, 67],
>        slide: function(event, ui) {
>                $("#amount0").html('$' + ui.values[0] + ' - $' +
> ui.values[1]);
>        },
> });
>
> in the slide event, ui or event, are both objects but i don't understand in
> the source code how to use them.
>
> in the documentation, there seems to be 2 properties : ui.handle and
> ui.value. ui.handle juste returns "http://localhost/#"; and ui.values[0]
> gives me the value but not the position of the handle.
>
> I tried
>        $("#sliderposition").html($("#slider0 a:first").css("left"));


ui.handle is a DOMElement. It's an anchor element, the actual handle that
you're sliding around. You can get the left value like this

$(ui.handle).css("left")


> on the slide event but the values are wrong. Not to much but always 1% more
> or less. depending the direction the slider moved.


This is actually because of a feature of the slide event. Turns out it was
undocumented (by accident), so I've updated the documentation:

http://docs.jquery.com/UI/Slider#event-slide

"Return false in order to prevent a slide, based on ui.value."

That means in the slide event, the ui.value is not the actual value of the
handle, it's the future value the user is attempting to move to. So the
handle doesn't have the new css left value yet (it won't get it until after
your callback function doesn't return false). If it did, you'd get a weird
flicker when you move the handle to an invalid value, then the slide
callback returns false and the handle goes back.


> can anyone help please ?


Assuming your slider min and max are at the defaults, 0 and 100, ui.value is
a percentage already (well, just divide by 100). Otherwise, can you provide
some more detail as to why you're trying to get the position of the element?
That may make it easier to help.

- Richard

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to