# v-intersection

> vue directive use Intersection Observer API

Latest version **0.1.6** (published 2021-04-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install v-intersection
pnpm add v-intersection
yarn add v-intersection
bun add v-intersection
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2021-04-06 |
| First published | 2020-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | genjixyz |
| Maintainers | genji.xyz |
| Keywords | intersection, observe |

## Links

- npm: https://www.npmjs.com/package/v-intersection
- Repository: https://github.com/genjiXYZ/v-intersection
- Homepage: https://github.com/genjiXYZ/v-intersection#readme
- Issues: https://github.com/genjiXYZ/v-intersection/issues
- npm.io page: https://npm.io/package/v-intersection

## Dependencies (1)

- [core-js](https://npm.io/package/core-js.md) ^3.6.5

## Recent versions

- 0.1.6 (latest) — 2021-04-06
- 0.1.5 — 2021-04-06
- 0.1.3 — 2020-11-20
- 0.1.2 — 2020-11-20
- 0.1.1 — 2020-11-20
- 0.1.0 — 2020-11-20
- 0.0.1 — 2020-11-20

## README

# v-intersection

---

a vue component for IntersectionObserver

一个 vue 的 IntersectionObserver 组件

support vue3.0

[![npm](https://nodei.co/npm/v-intersection.png)](https://www.npmjs.com/package/v-intersection)

## demo and document


[demo and documment github page](https://genjixyz.github.io/v-intersection/)

[demo and documment 国内](https://coding-pages-bucket-144121-8040028-5553-382057-1259347617.cos-website.ap-hongkong.myqcloud.com/)  


## use

### install :

```dash
npm install v-intersection --save
```

### import:

vue 2.6.11
```js
import Vue from 'vue'
import intersection from "v-intersection";
Vue.use(intersection);
```

vue 3.0

```js
import intersection from "v-intersection";
createApp(App).use(intersection ).mount('#app')
```

### use

```html
vue directive

<div v-intersection="handler"></div>



<script>
export default {
  methods:{
	  handler(entries, observer, isIntersecting, ratio){

	  }
  }
};
</script>
```



### options:

```html
<div
  v-intersection="{handler:yourMehtod,
      options = {
        root: document.querySelector('#scrollArea'),
        rootMargin: '0px',
        threshold: [0,1]  
      }
  }"
>

</div>
```





more options info  in   [MDN document](https://developer.mozilla.org/zh-CN/docs/Web/API/IntersectionObserver)

更多配置参数请见 [MDN document](https://developer.mozilla.org/zh-CN/docs/Web/API/IntersectionObserver)



### modifier

```html

once
just run once ,and  IntersectionObserver.unobserve( target) 
只执行一次, 执行结束后 , IntersectionObserver.unobserve(target)
<div v-intersection.once="handler"></div>


quiet
don't handle  when binding directive 
在绑定指令时不触发, 
<div v-intersection.quiet="handler"></div>

```





## disconect( )  

```html
<div v-intersection="handler" ref="mydom"></div>


<button @click="disconect">  disconect( )  </button>


<script>
export default {
  methods:{
	  handler(entries, observer, isIntersecting, ratio){
	  },
    disconect(){
      this.$refs.mydom._observe.observer.disconnect() 
    }
  }
};
</script>

```



## unobserved ( ) 

```html
<div v-intersection="handler" ref="mydom"></div>



<button @click="unobserved">  unobserved( )  </button>


<script>
export default {
  methods:{
    
	  handler(entries, observer, isIntersecting, ratio){
	  },
    
    unobserved(){
      var observer = new IntersectionObserver(callback);
			observer.observe(this.$ref.mydom)
    }
  }
};
</script>


```

---
_Source: https://npm.io/package/v-intersection · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
