I am trying to set a box A to jump to the same x-position as box B. How do I do this? I tried the following but it does not work (the second line):
我试图设置一个方框A跳到与方框B相同的x位置。我该怎么做?我尝试了以下但它不起作用(第二行):
$("#boxa").animate({
left: $("#boxb").left
}, 1000, function() { });
});
Thanks,
Sam
2 个解决方案
#1
30
either
$('#boxB').css('left');
or
$('#boxB').offset().left;
#2
4
For properties specified in pixels, using:
对于以像素指定的属性,使用:
$('#boxB').css('padding-left');
gives a string like: '22px'
给出一个字符串:'22px'
Maybe it's better to use:
也许最好使用:
parseInt($('#boxB').css('padding-left'), 10);
in such cases, which gives a number like 22 .
在这种情况下,给出一个像22的数字。
#1
30
either
$('#boxB').css('left');
or
$('#boxB').offset().left;
#2
4
For properties specified in pixels, using:
对于以像素指定的属性,使用:
$('#boxB').css('padding-left');
gives a string like: '22px'
给出一个字符串:'22px'
Maybe it's better to use:
也许最好使用:
parseInt($('#boxB').css('padding-left'), 10);
in such cases, which gives a number like 22 .
在这种情况下,给出一个像22的数字。