spyes

1.0.1 • Public • Published

Spyes

Detect when a DOM element changes size or position.

Installation

Node.js

npm install spyes --save

Browser

Local

<script src="node_modules/spyes/dist/spyes.min.js"></script>

CDN unpkg

<script src="https://unpkg.com/spyes/dist/spyes.min.js"></script>

Example

const spyes = require('spyes');
 
new spyes(document.getElementById('my-element'))
    .onSize((newSize, oldSize)=> console.log('size changed', newSize, oldSize))
    .onPosition((newPosition, oldPosition)=> console.log('position changed', newPosition, oldPosition));

API

Spyes

Kind: global class

new Spyes(element, [opts])

Create instance

ParamTypeDefaultDescription
elementString | Element

element that you want watch

[opts]Object

configuration object

[opts.autoWatch]booleantrue

auto watch

[opts.checkMs]number50

interval in milliseconds for every check

[opts.unwatchAfterSize]booleanfalse

stop check after detect element resize

[opts.unwatchAfterPosition]booleanfalse

stop check after detect element position

spyes.sizeIsChanged() ⇒ boolean

Check if size is changed

Kind: instance method of Spyes

spyes.positionIsChanged() ⇒ boolean

Check if position is changed

Kind: instance method of Spyes

spyes.watch() ⇒ Spyes

Start watching

Kind: instance method of Spyes

spyes.unwatch() ⇒ Spyes

Stop watching

Kind: instance method of Spyes

spyes.onSize(callback) ⇒ Spyes

Fired when element changes size

Kind: instance method of Spyes

Param
callback

spyes.onPosition(callback) ⇒ Spyes

Fired when element changes position

Kind: instance method of Spyes

Param
callback

Changelog

You can view the changelog here

License

spyes is open-sourced software licensed under the MIT license

Author

Fabio Ricali

Package Sidebar

Install

npm i spyes

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

45.2 kB

Total Files

11

Last publish

Collaborators

  • fabioricali