[英]How to get height of a div in sencha touch 2?
I need to get the height of a div 我需要获得div的高度
I did it with plain js like: 我用普通的js做到了:
var inner = document.getElementById("inner").offsetHeight;
but, doesn't work when i am in another tab, so I try to use Ext
. 但是,当我在另一个选项卡中时不起作用,因此我尝试使用
Ext
。
I try this, but doesn't work: 我尝试这样做,但是不起作用:
var innerdiv = Ext.DomQuery.selectNode("inner");
var inner = innerdiv.getHeight();
I couldn't find any example. 我找不到任何例子。
which is the best way to get the height of a div? 哪个是获得div高度的最佳方法?
When using Ext.DomQuery.selectNode
, you have to have your selector right. 使用
Ext.DomQuery.selectNode
,必须具有选择器权限。 If inner
is an ID, you need a #
in front of it: 如果
inner
是ID,则需要在其前面加上#
:
var innerHeight = Ext.DomQuery.selectNode("#inner").getHeight();
尝试像
Ext.DomQuery.selectNode("#test").offsetHeight
I found a working example here. 我在这里找到了一个可行的例子。
var dimSz = Ext.get('dim-sizing');
var padding = dimSz.getPadding('lrtb'); // has value of 0px
var border = dimSz.getBorderWidth('lrtb'); // has value of 0px
var height = dimSz.getHeight(); // has value of 1691px
var width = dimSz.getWidth(); // has value of 895px
First get the DIV id with Ext.get, then get its dimensions with the functions. 首先使用Ext.get获取DIV ID,然后使用函数获取其尺寸。
Still doesn't work if the DIV is in a different (not visible) tab, (probably because the height of the DIV is 0) 如果DIV位于其他(不可见)选项卡中,则仍然不起作用(可能是因为DIV的高度为0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.