这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

borderBoxSize 只读特性在 ResizeObserverEntry interface returns an array containing the new border box size of the observed element when the callback is run.

句法

var myBorderBoxSize = ResizeObserverEntry.borderBoxSize;
					

An array containing objects with the new border box size of the observed element. The array is necessary to support elements that have multiple fragments, which occur in multi-column scenarios. Each object in the array contains two properties:

blockSize
The length of the observed element's border box in the block dimension. For boxes with a horizontal writing-mode , this is the vertical dimension, or height; if the writing-mode is vertical, this is the horizontal dimension, or width.
inlineSize
The length of the observed element's border box in the inline dimension. For boxes with a horizontal writing-mode , this is the horizontal dimension, or width; if the writing-mode is vertical, this is the vertical dimension, or height.

注意 : For more explanation of writing modes and block and inline dimensions, read Handling different text directions .

范例

const resizeObserver = new ResizeObserver(entries => {
  for (let entry of entries) {
    if(entry.borderBoxSize && entry.borderBoxSize.length > 0) {
      entry.target.style.borderRadius = Math.min(100, (entry.borderBoxSize[0].inlineSize/10) +
                                                      (entry.borderBoxSize[0].blockSize/10)) + 'px';
    } else {
      entry.target.style.borderRadius = Math.min(100, (entry.contentRect.width/10) +
                                                      (entry.contentRect.height/10)) + 'px';
    }
  }
});
resizeObserver.observe(document.querySelector('div'));
					

规范

规范 状态 注释
重置大小观测器
The definition of 'target' in that specification.
编者草案 初始定义。

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
borderBoxSize Chrome No Edge No Firefox 69 IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

元数据

  • 最后修改: