npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-on-intersect

v0.2.5

Published

Intersection Observer for Vue JS

Downloads

482

Readme

Vue-On-Intersect

** IN DEVELOPMENT ** Easily observe changes in an element's viewport location. Reuses observers, if multiple elements share the same offset for improved performance.

Designed to help you improve performance and integrate interactivity in response to an element's position on the page.

Example use cases:

  1. Trigger an animation on elements entering and exiting the viewport.
  2. Lazy loading an image when an element is 10% below the viewport.

See Demo.

This uses the Interaction Observer API

  • Make sure to include the polyfill to support older browsers.

Installation

npm install --save vue-on-intersect

Importing

Register Directive

import Vue from 'vue'
import VueOnIntersect from 'vue-on-intersect'

Vue.use(VueOnIntersect)

Usage

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

Declare the directive in your template with any of the following options:

| PropName | Type | Default | Description | | ------------ | :-----: | :------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | once | BOOLEAN | false | Update only on first intersect? | | topOffset | STRING | "0%" | When to trigger visibility updates. See Offsets for an explanation. | | bottomOffset | STRING | "0%" | When to trigger visibility updates. See Offsets for an explanation. | | threshold | NUMBER | 100 | A number indicating at what percentage(s) of the target's visibility the observer is updated. At the default of 100, updates will happen each percent increase/decrease in visibility from 0 - 100 |

<MyComponent v-on-intersect="options">

Vue-On-Intersect will update the reactive properties directly on your component.

| PropName | Type | Description | | ----------------- | :-----: | :------------------------------------------------- | | isIntersecting | BOOLEAN | Component is in viewport | | isAbove | BOOLEAN | Component is above viewport | | isBelow | BOOLEAN | Component is below viewport | | isPartiallyAbove | BOOLEAN | Component is in viewport, but also above viewport | | isPartiallyBelow | BOOLEAN | Component is in viewport, but also below viewport | | intersectionRatio | NUMBER | Amount of component visible. Decimal between 0 - 1 |

Make sure to subscribe to these reactive properties by the declaring them in your component's data object or using the VueOnIntersect Mixin.

import {VueOnIntersectMixin} from 'VueOnIntersect'

export default {
  name: 'MyComponent',
  // USING MIXIN
  mixins: [VueOnIntersectMixin],
  data() {
    return {
      options: {
        once: false,
        topOffset: '-20%',
        bottomOffset: '-20%',
      }
      // DECLARING DIRECTLY IN YOUR COMPONENT
      isIntersecting: null,
      intersectionRatio: null,
      isAbove: null,
      isBelow: null,
      isPartiallyAbove: null,
      isPartiallyBelow: null
    }
  }
}

Offsets

The default offsets 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.

For visibility changes to trigger when an element is outside the viewport use a positive number.

// Visibility changes occur 10% above the top of the viewport, and 10% below the bottom of the viewport. Example Use: Lazy Loading.
const topOffset = '10%'
const bottomOffset = '10%'

For visibility changes to trigger when an element is inside the viewport use a negative number.

// Visibility changes occur 10% below the top of the viewport, and 10% above the bottom of the viewport. Example Use: Animating as element enters view.
const topOffset = '-10%'
const bottomOffset = '-10%'

This is a new package, in active development. Please submit any issues or feature requests here.