views:

325

answers:

2

I am trying to add next/previous buttons on a button click using the jQuery UI Slider. I found this code...

$("#down").click(function() {
  var s = $("#slider"), val = s.slider("value"), step = s.slider("option", "step");
  s.slider("value", val - step);
});

$("#up").click(function() {
  var s = $("#slider"), val = s.slider("value"), step = s.slider("option", "step");
  s.slider("value", val + step);
});

Here: http://osdir.com/ml/jquery-ui/2009-03/msg00617.html

However this only changes the value of the Slider, moving the slider handle, but it doesn't actually slide the element. Little help?

A: 

The code works fine as demonstrated in this Working Demo. Add /edit to the URL to see the code and play with the demo.

$(function() {

    $('#slider').slider({ change: alertValue });

    $("#down").click(function() {
      var s = $("#slider"), val = s.slider("value"), step = s.slider("option", "step");
      s.slider("value", val - step);
    });
    $("#up").click(function() {
      var s = $("#slider"), val = s.slider("value"), step = s.slider("option", "step");
      s.slider("value", val + step);
    });

});

function alertValue() {

alert("The value is : " + $("#slider").slider("value"));

}
Russ Cam
A: 

Ah, the 'change:' is what I needed! The problem was I am scrolling content with the slider and changing the the value alone will not scroll the content, it only moves the handle. To make sure the next/previous works I repeated the function from $('#slider').slider({slide:]) into $('#slider').slider({change:]).

Thanks a ton!

no problem, happy to help :) Please could you help the site keep running as it should and mark my answer as accepted (click on the tick underneath the vote counter on my answer). Also, avoid posting a response as an "answer" and use either the comments underneath a particular answer (if you have enough reputation to do so) or edit your question to provide the feedback. Thanks!
Russ Cam
My apologizes, I don't think I can accept the answer as I wasn't registered before. I just registered, is there a way I can make the answer accepted?
If registration has gone correctly, you should have the question (asked when you were unregistered) associated with your registered account. If you do, simply login and click on the accepted tick next to the answer. If you don't, no problem :) Take a look at the FAQ for more info on how SO works- http://stackoverflow.com/faq - oh and happy programming :)
Russ Cam