Socket
Socket
Sign inDemoInstall

v-intersect

Package Overview
Dependencies
12
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    v-intersect

Detect when element is visible or hidden on user viewport


Version published
Weekly downloads
141
decreased by-4.08%
Maintainers
1
Install size
22.0 MB
Created
Weekly downloads
 

Readme

Source

V-Intersect

version

Detect when element is visible or hidden on user viewport

Demo

Demo

Installation

NPM
npm install v-intersect --save
Yarn
yarn add v-intersect

Install the plugin into your Vue project:

import Vue from 'vue'
import VIntersect from 'v-intersect'

Vue.use(VIntersect)

or use the component and directive directly:

import Vue from 'vue'
import { VIntersectComp, VIntersectDir } from 'v-intersect'

Vue.directive('intersect', VIntersectDir)
Vue.component('v-intersect', VIntersectComp)

Usage

Directive

<div class="content" v-intersect="onIntersect">...</div>

The function will be called when the visibility of the element is changes.

onIntersect(observer){
    this.isVisible = observer.isIntersecting
    console.log(observer.entries)
}
  • isIntersecting: when it's true it means the element is visible on the screen, and false means it's hidden
  • entries: IntersectionObserverEntry

And if you want the function only called when element is visible you can use .enter modifier.

<div class="content" v-intersect.enter="onIntersect">...</div>

Options

<div class="content" v-intersect="{
    callback: onIntersect,
    options: {
        root: ...,
        rootMargin: ...,
        threshold: ...
    }
}">
</div>

For more details IntersectionObserver Options

Once

It will called the function once when the element is visible

<div class="content" v-intersect="{
    callback: onIntersect,
    once: true
}" />

Disabling the observer

<div class="content" v-intersect="{
    callback: onIntersect,
    disabled: true
}" />

Component

<v-intersect @change="onIntersect">
    <div class="content">...</div>
</v-intersect>

Events

NameDescription
changeevent fired when visibility of the element change
enterevent fired when the element is intersect (visible) on the screen
onceevent fired once when the elemnt is visible

Props

NameTypeDefaultDescription
rootString' 'MDN
rootMarginString'0px'MDN
threshold[Array, Number]0MDN
disabledBooleanfalseDisable the observer

Note: for root prop, you need to pass the element class or id i.e .content or #content

Polyfill

This plugin uses The IntersectionObserver API, and currently it is not available in all browsers (IE11, Safari and iOS Safari). If you intend to support these browsers, you can include WICG IntersectionObserver Polyfill to your bundle.

Keywords

FAQs

Last updated on 12 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc