2012-07-12 152 views
2

我试图设置滑块在滑动事件中的值。这里是我的代码:jquery滑块设置滑动后的值

$(document).ready(function() { 
      $("#slider").slider({ 

       min: 0, 
       max: 10000, 
       step: 1, // Use this determine the amount of each interval 
       values: [0], // The default range 
       slide: function (event, ui) { 
        var slider = $("#slider").slider({ 
         animate: true 
        }); 
        slider.slider('value', 500); 
       } 
      }); 
     }); 

我在想什么?我似乎无法设置动画并设置滑块的值。

编辑:好吧,现在我可以设置滑块的值,但它发生得太快。我希望它慢慢达到我设定的价值。这里是我的编辑代码:

$(document).ready(function() { 
      $("#slider").slider({ 

       min: 0, 
       max: 10000, 
       animate: "slow", 
       step: 1,// Use this determine the amount of each interval 
       // values: [0] // The default range 
       change: function (event, ui) { 
        $("#slider").slider('value', 500); 
       } 
      }); 
     }); 

我怎样才能使它慢慢移动到500,而不是设置它的时候了吗?

谢谢

回答

1

参考

jsFiddle

移动滑块按钮并将其释放后,滑块按钮将动画回到锁定值。

代码:

$(document).ready(function() { 

    $('#slider').slider({ 
     min: 0, 
     max: 10000, 
     // Values "fast", "normal", "slow", or duration can be used. 
     animate: 1500, 
     step: 1, 
     // Starting value is 500 
     value: 500, 
     animate: true, 
     change: function(){ 
      // This setTimeout will allow the slider to animated correctly. 
      setTimeout("$('#slider').slider('value', 500);", 350); 
     } 
    }); 

    // On page load, animate the slider to this value of 500. 
    $('#slider').slider('value', 500); 

}); 

状态更新:所谓海报所需的stop:事件,而不是在UI滑块的change:事件等具体要求,但没有视觉差看到什么时候使用。

+0

我不需要获取值,我需要将滑块光标设置为该值的动画。现在我可以设置滑块的值(我在此之后更新我的问题),但无法缓慢移动,光标跳转到我立即设置的值。 – Pabuc 2012-07-12 10:14:42

+0

Pabuc,我的答案现在有所不同。请查看jsFiddle并告诉我这是否与您正在寻找的内容更接近。 – arttronics 2012-07-12 18:28:15

+0

我能够通过使用停止而不是滑块的更改事件来解决我的问题。你可以编辑你的回复,我会批准它。 – Pabuc 2012-07-15 17:02:40