这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
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
writing-mode
, this is the vertical dimension, or height; if the writing-mode is vertical, this is the horizontal dimension, or width.
inlineSize
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. |
编者草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
实验。期望将来行为有所改变。
ResizeObserverEntry
borderBoxSize
contentBoxSize
contentRect
target