Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-on-visible

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-on-visible

vue-on-visible

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
increased by31.25%
Maintainers
1
Weekly downloads
 
Created
Source

Vue-On-Visible

A collection of Vue components aimed to help you create better interactions with elements as they enter and exit the viewport.

Demo

This uses the Interaction Observer API and includes a polyfill enabling support in the following browsers:

Chrome
Firefox
Safari
6+
Edge
Internet Explorer
7+
Opera
Android
4.4+

Table of contents

Installation

npm install --save vue-on-visible

Importing

Install Directive and Components

import Vue from 'vue'
import OnVisible from 'vue-on-visible'

Vue.use(OnVisible)

Animation

Using built-in component <AnimateOnVisible> for quick turnkey animations on visibility changes.

  <AnimateOnVisible>
    <YourComponentHere />
  </AnimateOnVisible>

See below for available props.

PropNameTypeDefaultDescription
animateAboveBOOLEANfalseAnimate when entering from above viewport?
animateBelowBOOLEANtrueAnimate when entering from below viewport?
animationTypeSTRINGfadeChoose from fade, slide, and zoom. More to come.
animationDurationNUMBER in ms650Duration of animations.
yoyoBOOLEANfalseRepeat animaton on entering and exiting?
offsetsOBJECT{top: '0%', bottom: '0%'}When to trigger visibility updates. See Offsets for an explanation.

Directive

Use the v-on-visible directive to integrate visibility updates into your own components.

Template:

  <YourComponent v-on-visible="{onUpdate, offsets, yoyo}" />
PropNameTypeDefaultDescription
onUpdateFunctionn/a - REQUIREDFunction to be called when visibility changes occur.
yoyoBOOLEANfalseRepeat animaton on entering and exiting?
offsetsOBJECT{top: '0%', bottom: '0%'}When to trigger visibility updates. See Offsets for an explanation.

Component:


const YourComponent = {
  name: 'OnVisibleMixin',
  data() {
    return {
      isVisible: null,
      offsets: {
        top: '0%', bottom: '0%' 
      },
      yoyo: true 
    }
  },
  methods: {
    onUpdate(item) {
      // Do something with values...
      // See Properties Section for properties available on an item.
    }
  }
}
  

Component

Using built-in component <OnVisible> with slot-scope for updates on visibility changes.

<OnVisible :offsets={} :yoyo="true">
  <div slot-scope="onVisible">
    <!-- SEE PROPERTIES SECTION BELOW FOR AVAILABLE PROPS -->
    <YourComponent isVisible="onVisible.isVisible" isBelow="onVisible.isBelow"/>
  </div>
</OnVisible>

Properties

The following properties will be send on all visibility updates:

PropNameTypeDescription
isVisibleBOOLEANComponent is in viewport
isAboveBOOLEANComponent is above viewport
isBelowBOOLEANComponent is below viewport
isPartiallyAboveBOOLEANComponent is in viewport, but also above viewport
isPartiallyBelowBOOLEANComponent is in viewport, but also below viewport
intersectionRatioNUMBERAmount of component visible. Decimal between 0 - 1
rectOBJECTObject with boundingRect properties

Offsets

The default offset will trigger visibility changes when your component enters/exits the viewport at the top or bottom. You can change this behavior by providing your own offsets object. Negative offsets are triggered inside of the viewport, while positive offsets are triggered outside the viewport.

// Place triggers 10% below the top of the viewport, and 10% above the bottom of the viewport.
{top: '10%', bottom: '10%'}

// Place triggers 10% above the top of the viewport, and 10% below the bottom of the viewport.
{top: '-10%', bottom: '-10%'}

This is still a work in progress so any feedback and or pull requests are welcome.

Keywords

FAQs

Package last updated on 21 Sep 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc