::: sourceCode
## uni.createIntersectionObserver(component, options?) @createintersectionobserver
> issues: https://issues.dcloud.net.cn/?mid=api.ui.createIntersectionObserver
> 源码: https://github.com/dcloudio/uni-app/tree/uni-app-x-alpha/src/uni_modules/uni-createIntersectionObserver
:::
创建并返回一个 IntersectionObserver 对象实例
### createIntersectionObserver 兼容性
### 参数
| 名称 | 类型 | 必填 | 兼容性 |
| :- | :- | :- | :-: |
| component | any | 是 | Android: x; iOS: x; HarmonyOS: x |
| options | **CreateIntersectionObserverOptions** | 否 | Android: x; iOS: x; HarmonyOS: x |
#### options 的属性描述
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
| :- | :- | :- | :-: | :- |
| thresholds | Array<any> | 否 | Android: x; iOS: x; HarmonyOS: x | 所有阈值 |
| initialRatio | number | 否 | Android: x; iOS: x; HarmonyOS: x | 初始的相交比例 |
| observeAll | boolean | 否 | Android: x; iOS: x; HarmonyOS: x | 是否同时观测多个参照节点(而非一个) |
| nativeMode | boolean | 否 | 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 需要基础库: `3.5.7`
是否使用原生观察器模式。
|
### 返回值
| 类型 |
| :- |
| [IntersectionObserver](#intersectionobserver-values) |
#### IntersectionObserver 的方法 @intersectionobserver-values
#### relativeTo(selector: string, margins?: any): IntersectionObserver; @relativeto
relativeTo
使用选择器指定一个节点,作为参照区域之一
##### relativeTo 兼容性
Android: x; iOS: x; HarmonyOS: x
##### 参数
| 名称 | 类型 | 必填 | 兼容性 |
| :- | :- | :- | :-: |
| selector | string | 是 | Android: x; iOS: x; HarmonyOS: x |
| margins | any | 否 | Android: x; iOS: x; HarmonyOS: x |
##### 返回值
| 类型 |
| :- |
| IntersectionObserver |
#### relativeToViewport(margins?: any): IntersectionObserver; @relativetoviewport
relativeToViewport
指定页面显示区域作为参照区域之一
##### relativeToViewport 兼容性
Android: x; iOS: x; HarmonyOS: x
##### 参数
| 名称 | 类型 | 必填 | 兼容性 |
| :- | :- | :- | :-: |
| margins | any | 否 | Android: x; iOS: x; HarmonyOS: x |
##### 返回值
| 类型 |
| :- |
| IntersectionObserver |
#### observe(targetSelector: string, callback: ObserveCallback): void; @observe
observe
指定目标节点并开始监听相交状态变化情况
##### observe 兼容性
Android: x; iOS: x; HarmonyOS: x
##### 参数
| 名称 | 类型 | 必填 | 兼容性 |
| :- | :- | :- | :-: |
| targetSelector | string | 是 | Android: x; iOS: x; HarmonyOS: x |
| callback | (result: [ObserveResult](#observeresult-values)) => void | 是 | Android: x; iOS: x; HarmonyOS: x |
##### ObserveResult 的属性值 @observeresult-values
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
| :- | :- | :- | :-: | :- |
| intersectionRatio | number | 是 | Android: x; iOS: x; HarmonyOS: x | 相交比例 |
| intersectionRect | any | 是 | Android: x; iOS: x; HarmonyOS: x | 相交区域的边界 |
| boundingClientRect | **ObserveNodeRect** | 是 | Android: x; iOS: x; HarmonyOS: x | 目标节点布局区域的边界 |
| relativeRect | **ObserveNodeRect** | 是 | Android: x; iOS: x; HarmonyOS: x | 参照区域的边界 |
| time | number | 是 | Android: x; iOS: x; HarmonyOS: x | 相交检测时的时间戳 |
#### boundingClientRect 的属性描述
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
| :- | :- | :- | :-: | :- |
| left | number | 是 | Android: x; iOS: x; HarmonyOS: x | left |
| right | number | 是 | Android: x; iOS: x; HarmonyOS: x | right |
| top | number | 是 | Android: x; iOS: x; HarmonyOS: x | top |
| bottom | number | 是 | Android: x; iOS: x; HarmonyOS: x | bottom |
#### relativeRect 的属性描述
| 名称 | 类型 | 必备 | 兼容性 | 描述 |
| :- | :- | :- | :-: | :- |
| left | number | 是 | Android: x; iOS: x; HarmonyOS: x | left |
| right | number | 是 | Android: x; iOS: x; HarmonyOS: x | right |
| top | number | 是 | Android: x; iOS: x; HarmonyOS: x | top |
| bottom | number | 是 | Android: x; iOS: x; HarmonyOS: x | bottom |
#### disconnect(): void; @disconnect
disconnect
停止监听
##### disconnect 兼容性
Android: x; iOS: x; HarmonyOS: x
### 示例
示例为[hello uni-app x alpha分支](https://gitcode.com/dcloud/hello-uni-app-x/blob/prod_alpha/pages/API/create-intersection-observer/create-intersection-observer.uvue),与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例[另见](https://gitcode.com/dcloud/hello-uni-app-x/blob/master//pages/API/create-intersection-observer/create-intersection-observer.uvue)
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/create-intersection-observer/create-intersection-observer
>示例
```vue
{{data.appear ? '小球出现' : '小球消失'}}
向下滚动让小球出现
```
:::
## 通用类型
### GeneralCallbackResult @generalcallbackresult-values
| 名称 | 类型 | 必备 | 描述 |
| :- | :- | :- | :- |
| errMsg | string | 是 | 错误信息 |