0.0.2 • Published 7 years ago

vue-mixin-in-viewport v0.0.2

Weekly downloads
15
License
MIT
Repository
github
Last release
7 years ago

vue-mixin-in-viewport

Vue 2.0 mixin to observe intersection using the Intersection Observer API

Note

This mixin requires the Intersection Observer API. In case you want to support older browsers, there is vue-mixin-in-viewport.polyfill.js which comes with a polyfill.

Installation

$ npm install vue-mixin-in-viewport

Usage

// without polyfill
import inViewportMixin from 'vue-mixin-in-viewport'

// with polyfill
import viewportMixin from 'vue-mixin-in-viewport/dist/vue-mixin-in-viewport.polyfill'

Vue.component('avatar-component', {
  template: '#avatar-component',
  mixins: [inViewportMixin]
})

```html
<avatar-component v-on:viewport="onViewportEnter"></avatar-component>

Props

NameTypeDefaultDescription
rootStringnullSelector specifying element that is used as the viewport for checking visiblity of the target.
rootMarginNumber0Margin around the root.
thresholdNumber0Indicates at what percentage of the target's visibility the observer's callback should be executed.
onceBooleanfalseFire only once.

Data

NameTypeDescription
inViewportBooleantrue if component is in viewport

Events

NameDescription
viewport-enterFire when target enters the viewport/root element.
viewport-changeFire when target enters or leaves the viewport/root element.
viewport-leaveFire when target leavs the viewport/root element.

License

MIT