GithubHelp home page GithubHelp logo

apertureless / vue-observable Goto Github PK

View Code? Open in Web Editor NEW
24.0 3.0 4.0 98 KB

IntersectionObserver, MutationObserver and PerformanceObserver in Vue.js

License: MIT License

JavaScript 94.03% Vue 5.97%
vue vuejs vuejs2 vue2 intersection-observer mutations-observer resize-images browser-api abstract components

vue-observable's Introduction

vue-observable

npm vue2

Abstract Vue Components to utilizing the IntersectionObserver, MutationObserver and ResizeObserver Browser APIs

๐Ÿ”ฅ Please keep in mind that you will need polyfills

๐Ÿ”ง Installation

npm install --save vue-observable

๐Ÿ‘ˆ Usage

Componentlist

Bundler (Webpack, Rollup)

import Vue from 'vue'
import VueObservable from 'vue-observable'

Vue.use(VueObservable)

or

import {Intersect, Mutation, Resize} from 'vue-observable'

export default {
  components: {Intersect, Mutation, Resize}
}

Browser

<!-- Include after Vue -->
<!-- Local files -->
<script src="vue-observable/dist/vue-observable.js"></script>

<!-- From CDN -->
<script src="https://unpkg.com/vue-observable"></script>

๐Ÿ“’ Components

IntersectionObserver - <intersect>

The <intersect> component will detect if a given element is in the viewport. And emit an event.

Props

Prop Required Default
root no null
rootMargin no 0px 0px 0px 0px
threshold no [0, 0.2]

Events

  • enter
  • leave
  • change

Usage

<intersect @enter="enterMethod" @leave="leaveMethod" @change="changeMethod">
  <some-component-or-node>
</intersect>

MutationObserver - <Mutation>

Props

Prop Required Default
attributeFilter no null
attributeOldValue no null
attributes no false
characterData no null
characterDataOldValue no null
childList no false
subtree no false

Events

  • mutation

Usage

<mutation @mutation="mutationMethod">
  <some-component-or-node>
</mutation>

ResizeObserver - <resize>

Props

N/A

Events

  • resize

Usage

<resize @resize="resizeMethod">
  <some-component-or-node>
</resize>

Development

Launch visual tests

npm run dev

Launch Karma with coverage

npm run dev:coverage

Build

Bundle the js and css of to the dist folder:

npm run build

Publishing

The prepublish hook will ensure dist files are created before publishing. This way you don't need to commit them in your repository.

# Bump the version first
# It'll also commit it and create a tag
npm version
# Push the bumped package and tags
git push --follow-tags
# Ship it ๐Ÿš€
npm publish

License

MIT

Support

Buy Me A Coffee

vue-observable's People

Contributors

apertureless avatar seanogdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-observable's Issues

Can't use a ref as root prop

First off, finding this really useful, so thank you.

However I've noticed I'm unable to pass in an element with a ref as the root prop in the <intersect> component.

The error I get is that HTMLDivElement is not of type Object. Is there any workaround I could use? I don't see any examples of that prop being used in the tests currently, so I'm a bit unsure on how to proceed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.