jQuery 使用jquery获取div左右值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4228916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get div left and right value using jquery
提问by X10nD
There is no left assigned for the div, I use $('#').css('left');
to get the left value, but it shows auto.
没有为 div 分配$('#').css('left');
左值,我用来获取左值,但它显示为自动。
How do I get the left value of the div.
如何获得 div 的左值。
Thanks Jean
谢谢让
回答by Orbling
The .css() command returns what the CSS setting is, so if you have 'auto' set, that is what you will see.
.css() 命令返回 CSS 设置是什么,所以如果你设置了“自动”,这就是你会看到的。
You can retrieve the computed position relative to the parent with $('#').position().left;
, 'top' also is available from position(), if you want the value relative to the document use $('#').offset().left
.
您可以使用 检索相对于父级的计算位置$('#').position().left;
,如果您想要相对于文档使用的值,'top' 也可从 position() 获得$('#').offset().left
。