可以使用以下两种方法获取 Dojo 中 DOM 节点的高度:

  1. 使用 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);
});
  1. 使用 dojo/dom-style 模块中的 getComputedStyle 方法:
require(["dojo/dom-style"], function(domStyle){
  var node = dom.byId("myNode");
  var height = domStyle.getComputedStyle(node).height;
  console.log(height);
});

注意:使用第二种方法获取的高度是字符串类型,需要进行转换

dojo domnode获取高度

原文地址: https://www.cveoy.top/t/topic/g9bE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录