jQuery动画和属性值百分比 [英] jQuery animate and property values in percentage

查看:458
本文介绍了jQuery动画和属性值百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为div设置动画,我尝试在其他地方使用某些值进行检索,我知道这个值是正确的,因为我已打印出输出...所以我想知道为什么它不能正常工作?

I trying to animate a div and I try to use some value retreived somewhere else, I know the value to be correct because I've printed out the output... so I'm wondering why doesn't it work properly?

animateBar(percentage.toFixed(2)+'%');

[ . . . ]

function animateBar(percentage)
{
    $('#innerBox').animate({width: percentage}, 3000);
}


推荐答案

好像是使用动画百分比的错误。 http://bugs.jquery.com/ticket/10669

It seems as though theres a bug with using a percentage with animate. http://bugs.jquery.com/ticket/10669

我建议计算自己添加的像素数,这可能有效:

I would suggest calculating the number of pixels to add yourself, something like this may work:

percent = 0.25;
add_width = (percent*$('#innerBox').parent().width())+'px';
$('#innerBox').animate({'width': '+='+add_width}, 3000);

这篇关于jQuery动画和属性值百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆