unobserve() 方法在 ResizeObserver interface ends the observing of a specified 元素 or SVGElement .

句法

void unobserve(target);
					

参数

target
A reference to an 元素 or SVGElement to be unobserved.

返回值

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);
checkbox.addEventListener('change', () => {
  if(checkbox.checked) {
    resizeObserver.observe(divElem);
  } else {
    resizeObserver.unobserve(divElem);
  }
});
					

规范

规范 状态 注释
重置大小观测器
The definition of 'unobserve()' 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
unobserve 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

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改:
  1. 重置尺寸观测器 API
  2. ResizeObserver
  3. 构造函数
    1. ResizeObserver()
  4. 方法
    1. disconnect()
    2. observe()
    3. unobserve()
  5. Related pages for Resize Observer API
    1. ResizeObserverEntry