vue-visibility-change

vue directive for detect page visibility-change
25,156 27
Install
npm install vue-visibility-change
Latest Version:1.2.1
Vue:2
License:MIT
Last Updated:Apr 2, 2019
Links: GitHub  ·  npm
Maintainer: xlaoyu

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

Related Packages

vue3-highlight-text

a vue3 directive of highlight text

84,789
vue-proportion-directive

vue 固定元素比例指令

6,003 10
ardirectives

Ardirectives

811
vue-on-click-outside

vue mixin/directive that does something when you click outside a container

169,297 31
vue-bind-once

A tiny, SSR-safe directive for binding random data to an element.

152,016 169

Version History

Version Released License
1.2.1 MIT
1.2.0 MIT
1.1.0 MIT
1.0.0 MIT