将JQuery动画附加到方法/设置器而不是CSS属性?

dri*_*iAn 4 jquery-ui jquery-animate

来自JQuery参考@ http://api.jquery.com/animate/:

 $('#book').animate({
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'   }, 5000, function() {
    // Animation complete.   
 });
Run Code Online (Sandbox Code Playgroud)

看起来我们只能修改真正的CSS属性,但是我希望我也能为JQuery对象属性设置动画.例如,我想为进度条的'value'属性设置动画:

http://jqueryui.com/demos/progressbar/#option-value

//setter
$('.selector').progressbar('option', 'value', 37);
Run Code Online (Sandbox Code Playgroud)

我找不到一种方法来为进度条的这个"值"属性设置动画,有没有办法这样做?

感谢帮助..

Fer*_*min 5

如果要设置动画值,你不能使用javascript setInterval()和clearInterval()方法吗?

你可以这样做:

var progressBar = $('#progress');           
var index=0;
var maxCount=100;
var theInterval = setInterval (function(){
    progressBar.progressbar({value:index});
    if (index == maxCount) {
        clearInterval(theInterval);
    }
    index++;
}, 100 );
Run Code Online (Sandbox Code Playgroud)

在上面的例子中,setInterval函数每100毫秒触发一次,每次只增加1,当它达到100时,clearInterval函数停止它的动画.