observe()
方法在
ResizeObserver
interface starts observing the specified
元素
or
SVGElement
.
resizeObserver.observe(target, options);
target
元素
or
SVGElement
to be observed.
box
content-box
(the default), and
border-box
.
Void.
None.
The following snippet is taken from the resize-observer-text.html ( see source ) example:
const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
if(entry.contentBoxSize) {
h1Elem.style.fontSize = Math.max(1.5, entry.contentBoxSize.inlineSize/200) + 'rem';
pElem.style.fontSize = Math.max(1, entry.contentBoxSize.inlineSize/600) + 'rem';
} else {
h1Elem.style.fontSize = Math.max(1.5, entry.contentRect.width/200) + 'rem';
pElem.style.fontSize = Math.max(1, entry.contentRect.width/600) + 'rem';
}
}
});
resizeObserver.observe(divElem);
An
observe()
call with an options object would look like so:
resizeObserver.observe(divElem, { box : 'border-box' });
| 规范 | 状态 | 注释 |
|---|---|---|
|
重置大小观测器
The definition of 'observe()' in that specification. |
编者草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
observe
|
Chrome 64 | Edge 79 | Firefox 69 | IE No | Opera 51 | Safari 13.1 | WebView Android 64 | Chrome Android 64 | Firefox Android No | Opera Android 47 | Safari iOS 13.4 | Samsung Internet Android 9.0 |
完整支持
不支持
ResizeObserver
disconnect()
observe()
unobserve()