简体   繁体   English

如何使用JQuery获取CSS属性的值?

[英]How to get the value of a CSS property using JQuery?

I am trying to set a box A to jump to the same x-position as box B. How do I do this? 我想设置一个方框A跳到与方框B相同的x位置。我该怎么做? I tried the following but it does not work (the second line): 我尝试了以下但它不起作用(第二行):

$("#boxa").animate({
   left: $("#boxb").left
}, 1000, function() { });
});

Thanks, 谢谢,

Sam 山姆

either

$('#boxB').css('left');

or 要么

$('#boxB').offset().left;

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的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM