Socket
Socket
Sign inDemoInstall

vue-observe-visibility

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-observe-visibility

Detect when an element is becoming visible or hidden on the page.


Version published
Weekly downloads
389K
increased by9.89%
Maintainers
1
Weekly downloads
 
Created

What is vue-observe-visibility?

The vue-observe-visibility package is a Vue.js directive that allows you to detect when an element is visible or hidden in the viewport. This can be useful for lazy loading images, infinite scrolling, or triggering animations when elements come into view.

What are vue-observe-visibility's main functionalities?

Basic Visibility Detection

This feature allows you to detect when an element becomes visible or hidden in the viewport. The `visibilityChanged` method is called with a boolean indicating the visibility state and the IntersectionObserverEntry object.


<template>
  <div v-observe-visibility="visibilityChanged">
    Content to observe
  </div>
</template>

<script>
export default {
  methods: {
    visibilityChanged(isVisible, entry) {
      console.log('Element is visible:', isVisible);
    }
  }
};
</script>

Threshold Configuration

This feature allows you to configure the threshold at which the visibility change is detected. In this example, the `visibilityChanged` method is called when 50% of the element is visible.


<template>
  <div v-observe-visibility="{ handler: visibilityChanged, options: { threshold: 0.5 } }">
    Content to observe
  </div>
</template>

<script>
export default {
  methods: {
    visibilityChanged(isVisible, entry) {
      console.log('Element is visible:', isVisible);
    }
  }
};
</script>

Root Margin Configuration

This feature allows you to configure the root margin, which is the margin around the root element. In this example, the `visibilityChanged` method is called when the element is within 50px of the bottom of the viewport.


<template>
  <div v-observe-visibility="{ handler: visibilityChanged, options: { rootMargin: '0px 0px -50px 0px' } }">
    Content to observe
  </div>
</template>

<script>
export default {
  methods: {
    visibilityChanged(isVisible, entry) {
      console.log('Element is visible:', isVisible);
    }
  }
};
</script>

Other packages similar to vue-observe-visibility

Keywords

FAQs

Package last updated on 28 Dec 2020

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