dojo domnode获取高度
可以使用以下两种方法获取 Dojo 中 DOM 节点的高度:
- 使用
dojo/dom-geometry模块中的getMarginBox方法:
require(["dojo/dom-geometry"], function(domGeometry){
var node = dom.byId("myNode");
var box = domGeometry.getMarginBox(node);
var height = box.h;
console.log(height);
});
- 使用
dojo/dom-style模块中的getComputedStyle方法:
require(["dojo/dom-style"], function(domStyle){
var node = dom.byId("myNode");
var height = domStyle.getComputedStyle(node).height;
console.log(height);
});
注意:使用第二种方法获取的高度是字符串类型,需要进行转换
原文地址: https://www.cveoy.top/t/topic/g9bE 著作权归作者所有。请勿转载和采集!