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

IntersectionObserver interface's read-only rootMargin property is a string with syntax similar to that of the CSS margin property. Each side of the rectangle represented by rootMargin is added to the corresponding side in the root 元素的 bounding box before the intersection test is performed. This lets you, for example, adjust the bounds outward so that the target element is considered 100% visible even if a certain number of pixels worth of width or height is clipped away, or treat the target as partially hidden if an edge is too close to the edge of the root's bounding box.

The root element and root margin in 交集观测器 API for a more in-depth look at the root margin and how it works with the root's bounding box.

句法

var marginString = IntersectionObserver.rootMargin;
					

A string, formatted similarly to the CSS margin property's value, which contains offsets for one or more sides of the root's bounding box. These offsets are added to the corresponding values in the root's bounding box before the intersection between the resulting rectangle and the target element's bounds.

The string returned by this property may not match the one specified when the IntersectionObserver was instantiated. The browser is permitted to alter the values

rootMargin isn't specified when the object was instantiated, it defaults to the string "0px 0px 0px 0px" , meaning that the intersection will be computed between the root element's unmodified bounds rectangle and the target's bounds. The root element and root margin in 交集观测器 API describes how the rootMargin is used in more detail.

规范

规范 状态 注释
Intersection Observer
The definition of 'IntersectionObserver.rootMargin' in that specification.
工作草案 初始定义

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
rootMargin Chrome 51 Edge 15 Firefox 55 IE 不支持 No Opera Yes Safari 12.1 注意事项
12.1 注意事项
rootMargin does not work with <iframe>
WebView Android 51 Chrome Android 51 Firefox Android ? Opera Android ? Safari iOS 12.2 注意事项
12.2 注意事项
rootMargin does not work with <iframe>
Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

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

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

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

元数据

  • 最后修改: