我们如何使用我通过一些计算推导出的数量为对象设置动画?
$(document).ready(function(){
var someNumber = "'+='" + 500 + "'";
$('.someClass').animate(
{left:someNumber},
{duration : 500, queue : false},
function(){
});
});
这是 fiddle :
http://jsfiddle.net/H7hpP/
为什么元素没有动画?
P.S 如果我必须对两个对象应用相同的动画,以下是否有效?我记得在某处看到过:
$('#firstPage #secondPage').animate(
{css property},
{duration},
function(){});
初学者的问题,但这就是我使用 jQuery 的经验。
最佳答案
1.) 您不需要在字符串中添加 ':var someNumber = "+="+ 500 + "px";
2.) 你应该定义动画的单位,px, em, %
3.) 选择一个实际存在的元素:)
编辑
就像在 css 中一样,您可以使用 ,
选择多个对象
$('#first, #second, #third').animate()
$('#firstPage #secondPage')
将在 ID 为 firstPage
的元素中查找 ID 为 secondPage
的元素
关于javascript - 使用生成的数字为对象的左侧位置设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17360578/