---
name: "IntersectionObserver.disconnect"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.10.0" }
title: "disconnect"
---

## IntersectionObserver.disconnect

> [VERSION] Base Library >= 2.10.0

### Description

Stop observing; the callback will no longer be invoked

### Parameters

None


### Return Value

Type: `IntersectionObserver`

[IntersectionObserver instance](/en/miniapp/develop/miniapp/api/tyml/IntersectionObserver/IntersectionObserver)

### Examples

#### Stop listening on page unload

```html
// index.tyml
<view class="target">Target</view>
```

```js
// index.js
Page({
  data: {
    observer: null,
  },
  onReady() {
    var observer = ty.createIntersectionObserver(this);
    observer
      .relativeToViewport()
      .observe('.target', (res) => {
        console.log('Intersection ratio', res.intersectionRatio);
      });
    this.data.observer = observer;
  },
  onUnload() {
    if (this.data.observer) {
      this.data.observer.disconnect();
    }
  },
});
```

```css
// index.tyss
.target {
  height: 200rpx;
  background-color: #e8f4ff;
  margin-top: 600rpx;
}
```
