Socket
Socket
Sign inDemoInstall

vue-visibility-change

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue-visibility-change

vue directive for detect page visibility-change


Version published
Weekly downloads
1.7K
increased by2.83%
Maintainers
1
Install size
8.19 kB
Created
Weekly downloads
 

Readme

Source

v-visibility-change

Vue 2.x npm npm-downloades license

Page Visibility API wrapper for vuejs.

Features

  • no denpendencies
  • support vue directive && global callback
  • detect page visibility state
  • full tests in chrome, theoretically compatible with IE > 10, Firefox > 10, Safari > 6.1

Usage

install

npm
$ npm i vue-visibility-change -S
script

可以直接使用script标签引入

<script src="./lib/vue-visibility.js"></script>

global

import Vue from 'vue';
import visibility from 'vue-visibility-change';

// registry directive
Vue.use(visibility);

// global mode
const handler = visibility.change((evt, hidden) => {
  // do something
});

visibility.hidden(); // Return true if page now isn’t visible to user.

visibility.unbind(handler); // Remove `change` listener by it's handler.

visibility.isSupported(); // Return true if browser support Page Visibility API.

vue-directive

<template>
  <div v-visibility-change="visibilityChange">
  </div>
</template>
<script>
export default {
  methods: {
    visibilityChange(evt, hidden) {
      // do something
      console.log(hidden);
    }
  }
};
</script>

Demo

visit Demo page, open console pane in the lower right corner, switch broswer tab to see output.

demo.gif

License

MIT

Copyright (c) 2017-present, xlaoyu

Keywords

FAQs

Last updated on 02 Apr 2019

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